-1
问题,说我有一个文件,它看起来像这样:有关文件输入流
x 1
y 2
z 3
什么即时试图做的是通过文件循环,并将其存储变量称为标头,里面当过头等于为“X”,“Y”或“Z”,我想在它后面的数字存储变量名为值像这里面:
string header;
string value;
ifstream readFile("filename.txt");
while (!readFile.eof()) {
readFile >> header;
if (header == "x") {
//store 1 to value
}
else if (header == "y") {
//store 2 to value
}
else if (header == "z") {
// store 3 to value
}
}
有人可以帮我请,我不能想出一个办法来实现它
[为什么'而(!readfile.eof())'是错误的(http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered -错误) – Barmar