写入文件时需要帮助获取新行
Need Help Getting New Line When Writing to File
我有endl,但它不会进入我的文件,所以当我输入超过1行时,它都在记事本的同一行上。
我试过:
代码文件<<代码行; 代码文件<<endl;
我还尝试通过向字符串添加常量字符串来向字符串添加"",但它不起作用。
//Writing Coded Lines to File:
if(codeFile)
{
//Relaying Feedback to User:
cout << "File has been successfully opened/created" << endl;
cout << "nWriting to file..." << endl;
for(int i = 0; i < lines; i++)
{
//Getting Non-Coded Line from User:
cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n');
cin.getline(line, length);
//Creating Copy of Line:
strcpy(cline, line);
//Gathering Line Length:
length = strlen(line);
//Coding Line:
codedLine = code(length, line, cline, sAlphabet);
//Coded Line Test
cout << codedLine;
//Writing to File:
codeFile << codedLine << endl;
}
}
//Closing File:
codeFile.close();
cout << "nFile has now been closed";
}
> Cygwin模拟了POSIX系统并使用Unix行尾,而不是记事本理解的Windows行尾。
用'n'
替换endl
无济于事。endl
是'n'
后跟流冲洗。
最好的选择是使用不同的文件阅读器,例如写字板,它可以理解Unix行尾。替代方案是
- 将编译器工具链更改为不模拟 POSIX 操作系统的工具链,或者
- 暴力破解以
rn
结尾的Windows行,但这意味着您的代码在基于Unix的系统上将出现类似的错误行尾问题。
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 我需要帮助在一个类中输入两个字符串并获取其输出
- 需要帮助使用类获取矩形和圆形的面积
- C++获取std::variant当前帮助的类型的std::typeindex
- 需要帮助从数组中获取特定值并将它们从最高到最低排序
- 看到' - '字符时我无法结束 getline,有人可以帮助我在 c++ 中获取 getline() ifstream
- 写入文件时需要帮助获取新行
- 需要帮助从文件中获取字符和整数数据
- 等待从获取锁的函数调用的帮助程序函数中的条件变量
- C++ 指针帮助缺少参数列表使用 &帐户::获取余额
- 如何在CTreeCtrl中获取所选项目的文件类型?文件扩展名可能被隐藏,因此 GetItemText 没有帮助
- 为不明确的符号获取错误,需要帮助将其删除
- 在获取CPU频率方面需要一些帮助
- 无法使用Qt助手从Qt应用程序内部获取自定义帮助文件
- 需要帮助获取数组中最小的三个数字
- HW帮助:获取字符而不是获取行c++
- 获取卷帮助
- GDAL GeoTiff获取标高在指定像素帮助c++
- 需要帮助获取ifstream::open以打开文件并从中获取行