I'm using VSCode for debugging my CPP program in MacOSX.
I've 2 programs.
Program1
int main(){
string a;
a = "a";
a += 'b';
cout<<a<<endl;
return 0;
}
Program2
int main(){
string a;
cin>>a;
a += 'b'
cout<<a;
return 0;
}
In program1 I'm directly assigning the string a
and when I debug the program in VSCode
by first compiling it in terminal using :
g++ -g filename.cpp
and then selecting the Starting Debugging option in the Debugging menu. I'm able to see the state of the string a
variable by moving forward in breakpoints.
The VARIABLES section shows the state of different variables and the CALL STACK show the stack frame.
But, for program2, when I go past the breakpoint of the cin>>a;
, the contents of VARIABLES and of CALL STACK get cleared up.
Here are the contents of the launch.json
file:
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
]
}
How can I get user-input and move forward to debug my code?
As stated in Here
if you enable "externalConsole":true in the launch.json then you will get a pop up console window that you can type in.
To debug with inputs, you can edit the arg section as shown below:
"program": "${workspaceFolder}/main",
"args": ["<", "input_file.in"]
The example above should be the same as: ./main < input_file.in
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With