Writer w("Output.txt");
w.writeString("The number of words in the script are: ");
w.writeInt(count);
w.writeEol();
w.writeString("The number of Officers in the script are: ");
w.writeInt(ofCount);
w.writeEol();
w.writeString("The number of Courtiers in the script are: ");
w.writeInt(cCount);
w.close();
作家.cpp
void Writer::writeEol()
{
out << "\n" << endl;
}
我的代码必须以这种方式实现,因为我的整个系统都是围绕它构建的。
所以我的问题是,如何调整 Writer::writeEol() 以向输出文件添加新行?
我的输出文件当前如下所示:
The number of words in the script are: 32339The number of Officers in the script are: 2The number of Courtiers in the script are: 9
任何帮助是极大的赞赏。 :)
如果没有正确的问题,我只能猜测您想学习什么,因此请随时用实际问题更新您的“问题”:
您实际上是在文件中写入两个换行符,具体取决于编码(即 Windows 或 Unix 换行符),您不会看到差异:
std::endl将自动包含正确的字符来创建换行符。没必要写"\n"以及。
而且你不必通过std::endl到流中,除非您确实想要在特定位置换行:
std::cout << "The result is: ";
std::cout << 50 << std::endl;