Ron*_*Ron 2 c++ file-io ofstream windows-8.1
在编写程序时,我遇到了一个奇怪的行为std::ofstream.请参阅下面的代码
ofstream dire;
dire.open("dir.txt", std::ios::out);
// some other code
for(int i=0;i<dir.size();i++)
{
dire << dir[i] << "\t"; // dir is integer vector containing values between 0-9
}
Run Code Online (Sandbox Code Playgroud)
现在,当我打开dir.txt内容时:
????????????????????????????????????????????????????????????.. and so on
Run Code Online (Sandbox Code Playgroud)
如果我给一个空格,然后选项卡(\ t)然后它正常工作或为此\n也正常工作. dire << dir[i] << " \t";
现在的输出是:
4 4 4 4 5 5 5 5 5 5.. and so on
Run Code Online (Sandbox Code Playgroud)
我也尝试dire.flush()将输出缓冲区刷新到文件,但结果仍然相同.
我绝对可以通过使用逃脱,\t但我想知道为什么会这样.
| 归档时间: |
|
| 查看次数: |
55 次 |
| 最近记录: |