已知一个unicode字符的编码值,如何根据这个编码值,输出对应的unicode字符到文本文件中
WCHAR ch = 0x4e00; //0x4e00就是已知的编码
ofstream outFile("test.txt");
如果直接按下面的方法输出的是数字:
outFile << ch;
请教大家,如何才能正确的输出字符到文件呢?
谢谢!!!
7 个解决方案
#1
在文件的开始处,写0xff0xfe
#2
C++流不支持输出unicode。google "如何升级基于STL的应用来支持Unicode"
#3
不行喔,写了还是乱码
#4
用api函数转换WideCharToMultiByte
转换后 再输出
转换后 再输出
#5
#include <iostream>
#include <fstream>
#include <iomanip>
#include <windows.h>
using namespace std;
int main()
{
WCHAR ch = 0x4e00;
ofstream outFile("test.txt",
ios::out | ios::app | ios::binary);
WORD uniFlag = 0xFEFF;
outFile.write((char *) &uniFlag, sizeof(uniFlag));
outFile.write((char *) &ch, sizeof(ch));
outFile.close();
return 0;
}
#include <fstream>
#include <iomanip>
#include <windows.h>
using namespace std;
int main()
{
WCHAR ch = 0x4e00;
ofstream outFile("test.txt",
ios::out | ios::app | ios::binary);
WORD uniFlag = 0xFEFF;
outFile.write((char *) &uniFlag, sizeof(uniFlag));
outFile.write((char *) &ch, sizeof(ch));
outFile.close();
return 0;
}
#6
#include <iostream>
#include <fstream>
#include <iomanip>
#include <windows.h>
using namespace std;
int main()
{
WCHAR ch = 0x4e00;
ofstream outFile("test.txt",
ios::out | ios::app | ios::binary);
WORD uniFlag = 0xFEFF;
outFile.write((char *) &uniFlag, sizeof(uniFlag));
outFile.write((char *) &ch, sizeof(ch));
outFile.close();
return 0;
}
#include <fstream>
#include <iomanip>
#include <windows.h>
using namespace std;
int main()
{
WCHAR ch = 0x4e00;
ofstream outFile("test.txt",
ios::out | ios::app | ios::binary);
WORD uniFlag = 0xFEFF;
outFile.write((char *) &uniFlag, sizeof(uniFlag));
outFile.write((char *) &ch, sizeof(ch));
outFile.close();
return 0;
}
#7
不需要
#1
在文件的开始处,写0xff0xfe
#2
C++流不支持输出unicode。google "如何升级基于STL的应用来支持Unicode"
#3
不行喔,写了还是乱码
#4
用api函数转换WideCharToMultiByte
转换后 再输出
转换后 再输出
#5
#include <iostream>
#include <fstream>
#include <iomanip>
#include <windows.h>
using namespace std;
int main()
{
WCHAR ch = 0x4e00;
ofstream outFile("test.txt",
ios::out | ios::app | ios::binary);
WORD uniFlag = 0xFEFF;
outFile.write((char *) &uniFlag, sizeof(uniFlag));
outFile.write((char *) &ch, sizeof(ch));
outFile.close();
return 0;
}
#include <fstream>
#include <iomanip>
#include <windows.h>
using namespace std;
int main()
{
WCHAR ch = 0x4e00;
ofstream outFile("test.txt",
ios::out | ios::app | ios::binary);
WORD uniFlag = 0xFEFF;
outFile.write((char *) &uniFlag, sizeof(uniFlag));
outFile.write((char *) &ch, sizeof(ch));
outFile.close();
return 0;
}
#6
#include <iostream>
#include <fstream>
#include <iomanip>
#include <windows.h>
using namespace std;
int main()
{
WCHAR ch = 0x4e00;
ofstream outFile("test.txt",
ios::out | ios::app | ios::binary);
WORD uniFlag = 0xFEFF;
outFile.write((char *) &uniFlag, sizeof(uniFlag));
outFile.write((char *) &ch, sizeof(ch));
outFile.close();
return 0;
}
#include <fstream>
#include <iomanip>
#include <windows.h>
using namespace std;
int main()
{
WCHAR ch = 0x4e00;
ofstream outFile("test.txt",
ios::out | ios::app | ios::binary);
WORD uniFlag = 0xFEFF;
outFile.write((char *) &uniFlag, sizeof(uniFlag));
outFile.write((char *) &ch, sizeof(ch));
outFile.close();
return 0;
}
#7
不需要