【发布时间】:2012-02-16 12:48:51
【问题描述】:
我正在用 C++ 逐行读取文本文件。我正在使用此代码:
while (inFile)
{
getline(inFile,oneLine);
}
这是一个文本文件:
-------
This file is a test to see
how we can reverse the words
on one line.
Let's see how it works.
Here's a long one with a quote from The Autumn of the Patriarch. Let's see if I can say it all in one breath and if your program can read it all at once:
Another line at the end just to test.
-------
问题是我只能阅读以“这是一个很长的等等......”开头的段落,并且它“立即停止:” 我无法解决阅读所有文本的问题。你有什么建议吗?
【问题讨论】:
-
您知道每次读取一行时都会覆盖
oneLine的内容,因此在while 循环终止后oneLine中的唯一内容是最后一行。 -
你并没有真正包含太多代码......