。 我是新来的C++。我必须找出文件包含的用户传递的编码类型。但我不知道如何检查文件的编码。所以我需要打印的文件是unicode或ansi或unicode big endian或utf8.I已经搜索了很多,但无法找到解决方案。到现在我已经做是我打开的文件:如何在C++中找到txt文件的编码?
#include "stdafx.h"
#include <iostream.h>
#include <stdio.h>
#include<conio.h>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
fstream f;
f.open("c:\abc.txt", fstream::in | fstream::out); /* Read-write. */
getch();
return 0;
}
所以请谁能告诉我的代码解决这个。
如果我正在访问记事本文件,该怎么办?
Thanx提前..
你不能找出使用哪种编码,你只能_predict_它。您应阅读以下内容:http://www.joelonsoftware.com/articles/Unicode.html –
如果文件具有BOM,请使用BOM。如果不是,请询问用户。这是确保的唯一方法。 –
@jonathan如何检查文件中的物料清单可以请您向我解释。 。 –