所以我想做一个愚蠢的小控制台响应的事情,因为我很无聊,但由于某种原因,它不接受它作为一个正确的答案每当你试图删除一些东西。该字符串看起来不错,但是当我试图用if(a==b)
或类似的东西检查它时,它不会有任何。下面的代码:输入似乎是把正确的字符串,但不被接受
string entry(){
string input = "";
char ch = getch();
while (ch != '\r'){
if (ch != '.'){
ch = tolower(ch);
input += ch;
cout<<ch;
ch = getch();
}
else if (ch == '.'){
cout<<ch;
ch=getch();
}
else if (ch == '\b'){
cout<<'\b';
input.resize((input.length()-1));
}
}
cout << "\n"+input;
return input;
}
这将通过类似a=entry();
使用,但是,正如我已经说过,它不为任何if
语句的工作。
当我按下退格键时打开了。 – LemenDrop
似乎有一个问题与input.resize((input.length() - 1));位。 – LemenDrop
@Xarathorn你可能需要检查'input'是否为空。 –