【发布时间】:2014-04-17 22:46:29
【问题描述】:
我正在尝试编写一个 getline 函数,该函数将从开放流中接收一串单词...我查看了不同的网站并尝试了它所说的操作,但我遇到了很多奇怪的错误。我需要 getline 来接收文件“内容”部分中的所有单词。这是我尝试过的,但我遇到了错误。
// Fill a single Tweet from a stream (open file)
// Returns true if able to read a tweet; false if end of file is encountered
// Assumes that each line in the file is correct (no partial tweets)
bool Tweet::FillTweet(ifstream &Din)
{
string tmp;
bool Success = false;
Din >> tmp;
if (!Din.eof())
{
Success = true;
date = tmp;
Din >> hashtag >> getline(Din,contents);
}
else
cout << "I don't want to read your tweet anyway. " << endl;
【问题讨论】: