C Getline首次通话后将跳过
C++ getline gets skipped after first call
本文关键字:Getline 更新时间:2023-10-16
char input_Handler(int& error,int user,const char satir[]){
string cheyeni;
int error_string = 0;
char che;
char test;
cout << "Please enter your move with keyboard letters such as 'A' or 'a'n";
//cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n');
//cin.ignore();
//
cin.ignore();
getline(cin,cheyeni);
........rest is not here
我有此功能可以处理游戏的输入。该功能在游戏中多次被称为。在第一次调用中,正确处理输入。但是,当再次被调用时,它的行为愚蠢。从我在网络上的搜索中,人们总是说getline在我按Enter时不会分配newline,所以当我再次调用时,它不会从我这里得到输入,而是从我的字符串中获得' n'(cheyeni)自动。
我似乎无法解决此问题,我尝试了多种cin.sync(),cin.ignore()。虽然您可能认为我确实错误地使用了它,但我在GetLine等之后尝试了很多方法。但是,我仍然可以/可能在某些事情上错了。我似乎看不到我缺少的部分。
用户期望输入一些字符串或字母。
将 cin.ignore()
放在 getline()
getline(cin,cheyeni);
cin.ignore();
相关文章:
- Seg Fault Issue C++ (file IO / getline)
- 当用户键入分隔符时,停止getline()输入
- getline() 的原型/库是什么;
- 错误 没有与参数列表匹配的重载函数"getline"实例
- 如何在 c++ 中使用 ',' 作为 getline 分隔符
- 错误:调用'getline'没有匹配函数
- 如何在 c++ 中使用 getline 从文件中读取字符串?
- 将 getline() 与文件一起使用
- 我有三个 getline,但是一旦编译,输入就太多了
- 在 std::getline 和 std::cin 期间卡在循环中
- 为什么 getline() 不读取文本文件中的所有内容?
- 有没有办法在不使用 getline() 的情况下从.csv文件中读取?
- 确切地说,如何解释 std::getline(stream, string) 函数在C++中填充的字符串
- std::getline没有在while循环中重新请求用户输入
- 谁能告诉我我用 getline 做错了什么 (cpp) 格式
- Getline(cin,str)的奇怪输出
- 我在C++中使用 getline() 函数时遇到问题
- 而循环跳过 cin.getline() 对于 C 字符串
- 如何在 getline 中删除/忽略超过特定数字的字符?
- 使用 getline(cin, var) 两次在进行字符串比较时会产生错误 (==)