求 C++ 最快的读取中文文件(UTF-8)的方式
求 C++ 最快的读取中文文件(UTF-8)的方式
我试过全部load 然后转成wchar_t 不知道还有更快的方式没, 正确答案给500分 先连开2贴
void LoadFile(const char * file)
{
//setlocale(LC_ALL, "zh_CN.UTF-8");
std::ifstream t;
t.open(file); // open input file
t.seekg(0, std::ios::end); // go to the end
bufferLen = t.tellg(); // report location (this is the length)
t.seekg(0, std::ios::beg); // go back to the beginning
buffer = new char[bufferLen]; // allocate memory for a buffer of appropriate dimension
t.read(buffer, bufferLen); // read the whole file into the buffer
t.close(); // close file handle
}
void UTF_8ToUnicode(char *pSrc,int start, int end)
{
pSrc+=start;
int srcLen=end-start;
int maxLineCount=100000;
lines=(wchar_t **)malloc(sizeof(wchar_t *)*maxLineCount); // at most 100000 lines
linesLength=(int *)malloc(sizeof(int)*maxLineCount); // at most 100000 lines
setlocale(LC_ALL, "en_US.UTF-8");
//setlocale(LC_ALL, "zh_CN.UTF-8");
wchar_t* pDst=(wchar_t *)malloc(sizeof(wchar_t)*(srcLen+1));
wstrLen=mbstowcs (pDst, pSrc, srcLen);
}