2014-09-22 74 views
-5

當我的程序第一次進入while(!looking)循環時,它會執行任務,但之後它不會繼續執行任務並翻譯它們。需要一些幫助,弄清楚爲什麼它不通過。程序不會繼續循環

while (cin.good()){ 
    getline(cin, lines); 
    while (!looking) { 
     spot = lines.find(" "); 
     if (spot == -1){ 
      looking = true; 
      spot = lines.length(); 
     } 
     line = lines.substr(0, spot); 
     TP1stLetter(line); 
     if (!looking) 
      lines = lines.substr(spot + 1, lines.length() - spot + 1); 
     } 
     cout << endl; 

//while(cin.good()) { 
    //getline (cin, line); 
    //for(x = 0; x < line.size(); x++) { 
     //char letter = line[x]; 
     //if (letter == 'a' || letter == 'e' || letter == 'i' 
     //  || letter == 'o' || letter == 'u'){ 
      //cout << letter; 
     //} 
    //} 
    } 
} 
+2

您是否嘗試逐行調試它? – 2014-09-22 18:49:55

+0

您是否期待我們「解析」您的整個工具? – 2014-09-22 18:50:39

+0

它看起來像你沒有重置'看'爲假 – Jake 2014-09-22 18:54:02

回答

2

就在cout聲明如下之後添加一行代碼:

if (mode == TOPIG) { 
cout << "TOPIG MODE" << endl; 
while (cin.good()){ 
    getline(cin, lines); 
    while (!looking) { 
     spot = lines.find(" "); 
     if (spot == -1){ 
      looking = true; 
      spot = lines.length(); 
     } 
     line = lines.substr(0, spot); 
     TP1stLetter(line); 
     if (!looking) 
      lines = lines.substr(spot + 1, lines.length() - spot + 1); 
    } 
    cout << endl; 
    looking = false; 

    //while(cin.good()) { 
    //getline (cin, line); 
    //for(x = 0; x < line.size(); x++) { 
    //char letter = line[x]; 
    //if (letter == 'a' || letter == 'e' || letter == 'i' 
    // || letter == 'o' || letter == 'u'){ 
    //cout << letter; 
    //} 
    //} 
    } 
} 
0

兩件事我能想到的,希望它有助於 - 如果你可以設置看着=在你的,而任何一點環路假的(看!)? - 你將在你的參數字符串報價在命令行中 這樣 YourExe.Exe these words are five arguments

但是相反,你需要的報價作出串 YourExe.Exe "this is one argument"

+0

論證是確定topig或frompig,但是在topig上工作;我希望用cin.good和getlines,我可以繼續要求翻譯的線條。你的意思是「你應該」還是「你不應該」? – John 2014-09-22 19:03:37