Qtファイルストリームのwhileループで>>演算子を使用するにはどうすればよいですか? (fin.atEnd()を使用する代わりに可能ですか?) 私がやりたいことは、行全体ではなく単語単位で単語をインポートすることです。ループ中にQtファイルストリームで>>演算子を使用する方法
QTextStream cout(stdout);
QTextStream cin(stdin);
int main()
{
//read & write a string to and from file
//open input file
QFile inData("input.txt");
inData.open(QIODevice::ReadOnly);
QTextStream fin(&inData); //setup file stream input
//open ouput file
QFile outData("output.txt");
outData.open(QIODevice::WriteOnly);
QTextStream fout(&outData); //setup file stream output
QString next;
//copy one file to another
while (fin >> next) ////////////////THIS LINE/////////////
{
next = fin.readLine();
next += '\n';
fout << next;
}
return 0;
}
ありがとう:ここに は私のコードは以下の、私は、問題の行をマークしているのですか?
この質問Read word by word from a text file in Qt4は単語のインポート部分を解決しますが、上記のように>>入力演算子を使用できるかどうかはまだ分かります。 (あなたがフィンのいずれかを使用することができ++標準C言語で>>()fin.eof次OR)operator>>
可能な複製を(http://stackoverflow.com/questions/9352708/read-word-by- text-file-in-qt4) – talamaki
なぜあなたは '' fin''''で 'next'を読んでいるのか、' next = fin.readLine(); '。他のすべての単語、または最初の単語がない行、またはそのようなものをすべて印刷しますか? –