C getline()函数无法按预期工作
C++ getline() function not working as intended
int boardDim(ifstream & inputFile, unsigned int x, unsigned int y) {
inputFile.open("test.txt");
if (!(inputFile.is_open())) {
throw fileNotOpen;
}
else {
stringstream output;
string output1;
if (getline(inputFile, output1)) {
output << output1;
if (output >> x) {
if (output >> y) {
return success;
}
return secBoardVarErr;
}
return firstBoardVarErr;
}
return lineErr;
}
cout << x << endl;
cout << y << endl;
}
输入文件包含两行int
s," 10 11"。
我正在返回Lineerr。我似乎无法弄清楚为什么我的getline()函数返回false。
写入output
流后,您就位于流的末尾。要再次读取数据,您需要寻找流的开始:
output.seekg(0, ios_base::beg);
顺便说一句,output
是您正在阅读的流的非常糟糕的名字。: - )
相关文章:
- getline() 上的分隔符无法正常工作
- 比较字符串的 GetLine 工作一次,然后比较之后不起作用
- 如何在使用getline后使cin工作
- 如何使 getline 命令在 while 循环中工作
- 对Getline的工作方式有更深入的深度
- C getline()函数无法按预期工作
- C STD :: getline / std :: Sort无法正常工作
- C++ while(getline()) 无法正常工作
- CIN.IGNORE如何与CIN和Getline一起工作
- cin.getline()函数在CIN之后无法正常工作
- C - getline stdin eof无法正常工作
- Getline 无法按预期使用字符串工作
- cin.getline()未按预期工作
- C++ cin.getline() 不能在循环中工作
- cout在获取行输入(getline)后无法在c++中工作
- Getline 无法按预期工作
- 通过getline()输入,正则表达式无法正常工作
- 我怎样才能让getline操作符工作
- Cin.getline 无法正确打印也无法正常工作
- std::getline() 访问冲突,以前可以工作,但现在无法从任何文件中读取