如何在写入文件时放置换行符 [英] How Can I place a Line Break while writing to a file
问题描述
我正在创建一个配置文件,点击下面的代码按钮。
$ b
fputs(AutoStart =+ strAutoWinStart +
AutLogHistory =+ strAutoLogSvrHistory +
AutoScan =+ strAutoScanDetect +
AutoMount =+ strAutoMount +
AutoOpen =+ strAutoOpenWin +
LastConnectedSvr =+ strAutoDetLastConSvr,pFile);
和输出文件如下所示:
< blockquote>
AutoStart = 1AutLogHistory = 0AutoScan = 1AutoMount = 0AutoOpen = 1LastConnectedSvr = 0
相反,我需要输出在每个参数中应该有一个换行符,如下所示:
AutoStart = 1
AutLogHistory = 0 >
AutoScan = 1
AutoMount = 0
AutoOpen = 1
LastConnectedSvr = 0
在UNIX样式的换行符中添加\r\\\
(或\\\
)以在文件。
Windows上的某些编辑器(如记事本)不能很好地处理UNIX样式的换行符,只显示一行内容。为了实现跨操作系统的最大可移植性,请使用\ n。为了在Windows中的最大可用性,使用\r\\\
。
更好:使用std :: ofstream和std :: endl - 你的问题被标记C ++毕竟。
I am creating a configuration file on click of a button by the following code.
fputs( "AutoStart = " +strAutoWinStart +
"AutLogHistory = " +strAutoLogSvrHistory +
"AutoScan= " +strAutoScanDetect +
"AutoMount = "+ strAutoMount +
"AutoOpen = "+ strAutoOpenWin +
"LastConnectedSvr = "+ strAutoDetLastConSvr,pFile);
and the Output file looks as below:
AutoStart = 1AutLogHistory = 0AutoScan= 1AutoMount = 0AutoOpen = 1LastConnectedSvr = 0
Instead I need my output should have a line break in each parameter and look as below:
AutoStart = 1
AutLogHistory = 0
AutoScan= 1
AutoMount = 0
AutoOpen = 1
LastConnectedSvr = 0
Add "\r\n" (or "\n" for UNIX-style linefeeds) to create a new line in the file.
Some editors on Windows such as Notepad don't handle UNIX-style linefeeds well, showing everything on one line. For the most portability across operating systems, use "\n". For the most usability in Windows, use "\r\n".
Even better: use std::ofstream with std::endl - your question is tagged C++ after all.
这篇关于如何在写入文件时放置换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!