所以我只是做一個程序,接受輸入並遇到錯誤;我嘗試過調試,但是當我使用std :: cout時,沒有消息讓我調試它。控制檯沒有響應?
int main()
{
try {
std::ifstream text_file;
ics::safe_open(text_file,"Enter file name to analyze","C:\\Users\\Xari\\Downloads\\program1\\graph1.txt");
Graph graph = read_graph(text_file);
print_graph(graph);
while (true) {
std::string input;
std::cout << "Enter the name of a starting node (enter quit to quit) D: ";
std::cin >> input;
std::cout << "INVISIBLE DEBUGGER MESSAGE" << std::endl;
if (input != "quit")
std::cout << "Reachable from node name " << input << " = " << reachable(graph, input) << std::endl;
else
break;
}
} catch (ics::IcsError& e) {
std::cout << e.what() << std::endl;
}
return 0;
}
問題是如果我輸入「a」,「b」輸出很好。如果我輸入c或更高,我不會收到消息回覆。即使是更奇怪的是,如果我在我的意見之後說得對,我仍然會得到同樣的問題,這是沒有意義的。
錯誤最有可能在可達函數中。如果你使用調試器,你可以看到。 – Joni
您的'Graph'可能已損壞,其遍歷功能有缺陷,或者'reachable'算法有缺陷。我們無法從您發佈的代碼中知道。你應該發佈一個最小但完整的,可編譯的程序來重現這個問題:在這種情況下,如果在print_graph調用之後簡單地調用std :: cout << reachable(graph,「c」),你可以完全拋棄輸入的東西。 ;'掛了。 –
也許嘗試使用'std :: getline(std :: cin,input);'而不是'std :: cin >> input;''getline()'會等到用戶輸入'ENTER',然後返回整個行輸入,而當用戶鍵入一個空白字符時,'std :: cin >>'將停止閱讀。 –