这篇文章的技术含量不是很高,就是一些常规做法,主要体现在细节上了,大家可以参考下。
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <string>
#include <sstream>
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
FILE *fp;
fp = _wfopen(L"1.txt", L"r");
if (fp == NULL)
{
fp=_wfopen(L"1.txt",L"w+b");
wchar_t m_strUnicode[1];
m_strUnicode[0] = wchar_t(0XFEFF);
fputwc(*m_strUnicode,fp);
}
fclose(fp);
wfstream file;
file.open("1.txt",ios::in|ios::out);
wcout.imbue(std::locale("chs"));
file.imbue(std::locale("chs"));
file<<L"ff中文\n";
wstring tmp;
file.close();
file.open("1.txt",ios::in|ios::out);
getline(file,tmp);
wcout<<tmp;
system("pause");
return 0;
}
因为unicode文件可以保证使用一种编码在全世界都不会出现乱码!