程序不会继续循环

时间:2014-09-22 18:48:47

标签: c++ loops while-loop

当我的程序第一次进入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 个答案:

答案 0 :(得分: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;
    //}
    //}
  }
}

答案 1 :(得分:0)

我能想到的两件事,希望它有所帮助 - 你应该在你的while(!look)循环中的任何一点设置look = false吗? - 您是否在命令行中的参数字符串周围添加引号 像这样 YourExe.Exe these words are five arguments

但你需要引号来制作一个字符串  YourExe.Exe "this is one argument"

相关问题