2014-09-22 75 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