yanyiwu / cppjieba

"结巴"中文分词的C++版本
MIT License
2.57k stars 690 forks source link

dict文件夹路径包含中文时崩溃 #169

Open siren186 opened 1 year ago

siren186 commented 1 year ago

cppjieba::Jieba构造函数如下,参数为std::string

Jieba(const string& dict_path, 
        const string& model_path,
        const string& user_dict_path, 
        const string& idfPath, 
        const string& stopWordPath) 

读取文件时,因为中文是以UTF-8编码存储在std::string中的,所以会造成找不到指定的文件,打开文件失败。

ifstream ifs(filePath.c_str());
HuangYoutian commented 1 year ago

同样问题,解决办法用不带中文的相对路径

YuHuanTin commented 1 day ago

读取文件时,因为中文是以UTF-8编码存储在std::string中的,所以会造成找不到指定的文件,打开文件失败。

尝试使用以下命令加在 main 函数第一句 std::locale::global(std::locale("zh_CN.UTF-8"));