BYVoid / OpenCC

Conversion between Traditional and Simplified Chinese
https://opencc.byvoid.com/
Apache License 2.0
8.36k stars 974 forks source link

使用visual studio 2022,utf8有bom,无法编译成功。 #711

Closed benojan closed 2 years ago

benojan commented 2 years ago

我下载的是wiki里的预编译:https://github.com/BYVoid/OpenCC/wiki/Download 使用下列代码编译:

#include <iostream>
#include "opencc/opencc.h"
using namespace std;
#pragma comment(lib, "opencc.lib")

int main()
{
    string str = "中华";
    const opencc::SimpleConverter converter("share\\opencc\\s2t.json");

    str = converter.Convert(str.c_str());

    system("chcp 65001");
    cout << "result is " << str << endl;
}

如果将上方代码以“无bom的utf8”保存,正常通过。 但是以“有bom的utf8”编码保存时,str = converter.Convert(str.c_str()); 就报错。

我最终是打算用于MFC程序内,MFC程序似乎只支持带BOM的utf8。

benojan commented 2 years ago

解決了,貌似是編碼問題

longlongvip commented 2 years ago

可以看下你的VS项目配置吗?