为什么 C++ 调试器会单步执行 VS Code 中的外部代码?

Pur*_*ale 4 c++ debugging visual-studio-code

#include<iostream>
#include<string>
using namespace std;

void reverse(string s){
    if(s.length()==0){ //base case
        return;
    }

    string ros=s.substr(1);
    reverse(ros);
    cout<<s[0];
}

int main(){
    reverse("binod");
    
}
Run Code Online (Sandbox Code Playgroud)

调试器_img_1

调试器_img_2

PFA,调试器应该进入reverse()函数。但它正在开放这些外部代码。

joh*_*ohn 6

调试器正在单步执行std::string(const char*)构造函数。您的代码在调用之前隐式调用此函数,reverse因为您将"binod"(实际上具有 type const char*)传递给需要std::string.

这里没有任何问题,这不是错误的函数,只是您没有意识到正在调用一个函数。只要走出去,然后再走进去。

旁注:Visual Studio 的调试器有“Just My Code!” 该功能启用后,意味着调试器只会进入您编写的代码。可以节省时间。