C++ C++;菲利奥奇怪的行为
在编写一个程序时,我遇到了一个奇怪的行为,即C++ C++;菲利奥奇怪的行为,c++,file-io,windows-8.1,ofstream,C++,File Io,Windows 8.1,Ofstream,在编写一个程序时,我遇到了一个奇怪的行为,即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 }
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
}
如果我先给空格,然后给制表符(\t),则它可以正常工作,或者\n也可以正常工作
dire如果您使用记事本查看文件,那么错误可能就是问题所在
当字符串不带其他字符传递给Win32字符集检测函数ISTEXTINCODE时,会发生此错误。IStextNicode看到它认为有效的UTF-16LE中文并返回true,然后应用程序错误地将文本解释为UTF-16LE
用十六进制编辑器打开dir.txt
。你看到了什么?这正是发生的事情,ऴ
在UTF-16LE中是0x3409,恰好与单字节编码中的4\t
相同。
ऴऴऴऴवववववववववशशशशशशशशशशषषषषषषषषरररररररऱऱऱऱऱऱऱऱऱललललललललललललळ.. and so on
4 4 4 4 5 5 5 5 5 5.. and so on