【发布时间】:2015-11-29 03:57:13
【问题描述】:
所以,我无法将文本文件中的最后一项读入字符串对象。
我创建了一个名为“Car”的类,我应该从文件中读取“Car”对象的所有参数,但它不会注册最后一个。
ifstream 对象是“数据”
变量是:
string carType;
string reportingMark;
int carNumber;
string kind;
bool loaded;
string destination;
文本文件中的行内容为:
汽车 CN 819481 维修假无
这就是我现在拥有的:
getline(data, ignore); // ignores the header line
data >> carType >> reportingMark >> carNumber >> kind >> loaded;
while (data.peek() == ' ') // this and the next lines were the suggestions of the teacher to bypass the spaces (of which there are more than it will display here)
data.get();
getline(data, destination);
因此,它将读取除“目标”部分之外的所有内容。
【问题讨论】:
-
我认为我们需要在您的代码和示例文件中查看更多上下文。
-
给你的“ifstream”对象一个while循环怎么样
-
详细了解
destination变量。它最终输出什么?是不是少了个字母?是空的吗?引发错误?奇怪的符号?