Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;菲利奥奇怪的行为_C++_File Io_Windows 8.1_Ofstream - Fatal编程技术网

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