C++ Getline和EOF

C++ Getline和EOF,c++,C++,我正在读一个文件。文件内容在一个句子中的单词之间有一个新行,在句子之间有两个新行。我只能读一句话。我曾尝试在getline中使用EOF作为分隔符,但似乎不起作用。有人对如何解决这个问题有什么建议吗 文件内容包括: 郡 宏伟的 陪审团 周五对亚特兰大最近的初选进行了调查 选举产生了``。没有证据“”。那有什么 违规行为发生了。陪审团在 市执行委员会提交的学期末陈述 但要打印的是: 郡 大陪审团周五表示,将对亚特兰大的 最近的初选产生了``。没有证据“”。那个 任何违规行为都发生了 . . 字符串

我正在读一个文件。文件内容在一个句子中的单词之间有一个新行,在句子之间有两个新行。我只能读一句话。我曾尝试在getline中使用EOF作为分隔符,但似乎不起作用。有人对如何解决这个问题有什么建议吗

文件内容包括:

宏伟的

陪审团

周五对亚特兰大最近的初选进行了调查
选举产生了``。没有证据“”。那有什么
违规行为发生了。陪审团在
市执行委员会提交的学期末陈述

但要打印的是:

大陪审团周五表示,将对亚特兰大的 最近的初选产生了``。没有证据“”。那个 任何违规行为都发生了 . .

字符串行;
a、b串;
ifstream infle(“myFile”);
while(getline(infle,line))
{
istringstream iss(线);
如果(!(iss>>a>>b)){break;}//错误
不能包含
#包括
#包括
使用名称空间std;
typedef boost::标记器
标记器;
无效打印短语(常量向量和短语){
if(!\u短语.empty()){
vector::const_迭代器it=_短语.begin();

你能给我们举一个文件内容的例子吗?你能给我们看一下输出吗?县大陪审团周五说,对亚特兰大最近的初选进行的调查产生了“没有证据”。表明发生了任何违规行为。陪审团在评论部分进一步说,不允许换行。请发布输出:富尔顿县大陪审团周五表示,对亚特兰大最近的初选进行的调查“没有证据”表明有任何违规行为发生。。
string line;
string a, b;
ifstream infile("myFile");

 while (getline(infile, line))
{
    istringstream iss(line);

    if (!(iss >> a >> b)) { break; } // error

    cout << a << b << endl;
}
#include <iostream>
#include <vector>
#include <boost/tokenizer.hpp>

using namespace std;

typedef boost::tokenizer<boost::char_separator<char>,
        std::istreambuf_iterator<char> >
    tokenizer;

void printPhrase(const vector<string>& _phrase) {
    if (!_phrase.empty()) {
        vector<string>::const_iterator it = _phrase.begin();
        cout << "Phrase: \"" << *it;
        for(++it; it != _phrase.end(); ++it)
            cout << "\", \"" << *it;
        cout << "\"" << endl;
    } else
       cout << "Empty phrase" << endl;
}

int main() {
    boost::char_separator<char> sep("", "\n", boost::drop_empty_tokens);
    istreambuf_iterator<char> citer(cin);
    istreambuf_iterator<char> eof;
    tokenizer tokens(citer, eof, sep);

    int eolcount = 0;
    vector<string> phrase;
    for (tokenizer::iterator it = tokens.begin(); it != tokens.end(); ++it) {
        if (*it == "\n") {
            eolcount ++;
            if (eolcount > 1 && eolcount % 2 == 0) { // phrase end
                printPhrase(phrase);
                phrase.clear();
            }
        } else {
            eolcount = 0;
            phrase.push_back(*it);
        }
    }
    if (!phrase.empty())
        printPhrase(phrase);
    return 0;
}