4
#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");
    
}

debugger_img_1

debugger_img_2

PFA, The debugger is supposed to step into the reverse() function. But it is opening these external codes.

ph0en1x
  • 68
  • 1
  • 13

1 Answers1

6

The debugger is stepping into the std::string(const char*) constructor. Your code calls this implicitly before calling reverse because you pass "binod" (which effectively has type const char*) to a function expecting a std::string.

There's nothing wrong here, it's not the wrong function, just a function you didn't realise was being called. Just step out and then step in again.

Side note: Visual Studio's debugger has the 'Just My Code!' feature which, when enabled, means the debugger only steps into code you wrote. Can be a useful time saver.

john
  • 85,011
  • 4
  • 57
  • 81
  • How to do that in VS Code? [reference](https://stackoverflow.com/questions/72894675/how-to-enable-just-my-code-setting-in-vscode-debugger) – ph0en1x Jul 13 '22 at 12:23