c++ - Debugging Going Too Far Into My Code -
i using visual studio 2013. i've never used debugger c++ code before, used utilize time programming msp430. anyways, i'm trying programming , trying utilize debugger step through code , follow logic of if/else statements. when seek utilize debugger this, 1 time begins going of prewritten c++ code terms such if, #include, ect. trying debugger ignore of standard c++ behind scenes details, , step through code. messed microsoft "my code only" feature, can't seem desire. worst case, guess have set breakpoint after after line want go through, curious if there easier method. thanks!
update:
here illustration code using test suggestions.
#include <iostream> #include <string> using namespace std; int main(){ cout << "line one\n"; cout << "line one\n"; cout << "line one\n"; cout << "line one\n"; cout << "line one\n"; cout << "line one\n"; cout << "line one\n"; cout << "line one\n\n"; string input; cin >> input; cout << "line one"; cout << "line one"; cout << "line one"; homecoming 0; }
it's nil pretty, i'm trying step first cout statement, see displayed in console window, click button, have display next cout statement, repeat, repeatedly.
i'm sure i'm not implementing suggestions correctly. when seek step out method, ends running of cout statements. because i'm trying cout operation, instead of logic tree, such if/whiles/ ect?
here's illogical mess i'm trying utilize method trace path through logic. it's pretty bad code, before scrap , rewrite it, trying figure out how step through , trace mess.
#include <iostream> #include <string> using namespace std; int main(){ string action; bool running = 1; int turn = 1; while (running){ //display map if (turn == 1){ //ask user input cout << "choose planet (ex: a1 or d4) or end turn: "; cin >> action; if (action == "end"){ if (turn == 1){ turn = 2; } else { turn = 1; } } } else{ cout << "it not turn"; turn = 2; } //change players turn } homecoming 0; }
i'm trying step through nested conditionals, because when run code prints "it not turn" ever. i'm pretty sure know real reason this, debugging snippets not purpose of question. :)
when stepping through code msvc debugger have 2 options (to used after setting breakpoint or having debugger started , programme paused somehow):
step (shortcut f11) step out (shortcut f10)the first enters in detail function calls, operator overrides, object construction , doesn't leave instruction until has been "stepped through", while latter want: "high level" overview skips in instruction can decomposed , "jumps" next instruction.
the "just code" used managed-feature it seems they've enabled native c++ well. can useful avoid pestering stack trace lots of unnecessary entries, step-in , step-out mechanism still holds.
edit: above works iff app compiled in debug mode. release mode optimized version for.. well.. releasing programs end-users. means won't have debugging info , setting breakpoints won't work expected.
for code above:
make sure you're compiling in debug mode (you can alter going project properties)
put breakpoint on first statement of main() function
launch debugger
when execution stops on line set breakpoint into, press f10 step next instruction
notice execution passed programme when step on console input operation allow digit on terminal screen. resume in debugger come in newline character.
c++ debugging
No comments:
Post a Comment