-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