Open playgithub opened 4 years ago
在VS2019上实验成功了。
项目代码:
#include <iostream>
#include<fstream>
#include "cppjieba/Jieba.hpp"
using namespace std;
int main()
{
char ch0[] = { "我喜欢吃苹果" };
const char* const DICT_PATH = "dict/jieba.dict.utf8";
const char* const HMM_PATH = "dict/hmm_model.utf8";
const char* const USER_DICT_PATH = "dict/user.dict.utf8";
const char* const IDF_PATH = "dict/idf.utf8";
const char* const STOP_WORD_PATH = "dict/stop_words.utf8";
cppjieba::Jieba jieba(DICT_PATH,
HMM_PATH,
USER_DICT_PATH,
IDF_PATH,
STOP_WORD_PATH);
vector<string> words;
vector<cppjieba::Word> jiebawords;
string s = ch0;
string result;
jieba.Cut(s, words, true);
ofstream file("result.txt");
file << limonp::Join(words.begin(), words.end(), "/") << endl;
file.close();
return 0;
};
- 不需要编译,直接把include和deps文件夹复制到项目中,然后在VS的include中添加。所以不要管demo。
对
- 源代码文件用UTF8编码(VS中新建时默认是936,可以用notepad++转换成UTF8)。分词结果用ofstream输出到文件再打开,不要输出到控制台,否则显示乱码。
对
- 如果使用C++20标准,那么limonp的StringUtils.hpp需要修改,因为not1和bind2nd几个函数在新标准中remove了。
是的,C++17也要改
在VS2019上实验成功了。
- 不需要编译,直接把include和deps文件夹复制到项目中,然后在VS的include中添加。所以不要管demo。
- 源代码文件用UTF8编码(VS中新建时默认是936,可以用notepad++转换成UTF8)。分词结果用ofstream输出到文件再打开,不要输出到控制台,否则显示乱码。
- 如果使用C++20标准,那么limonp的StringUtils.hpp需要修改,因为not1和bind2nd几个函数在新标准中remove了。
项目代码:
#include <iostream> #include<fstream> #include "cppjieba/Jieba.hpp" using namespace std; int main() { char ch0[] = { "我喜欢吃苹果" }; const char* const DICT_PATH = "dict/jieba.dict.utf8"; const char* const HMM_PATH = "dict/hmm_model.utf8"; const char* const USER_DICT_PATH = "dict/user.dict.utf8"; const char* const IDF_PATH = "dict/idf.utf8"; const char* const STOP_WORD_PATH = "dict/stop_words.utf8"; cppjieba::Jieba jieba(DICT_PATH, HMM_PATH, USER_DICT_PATH, IDF_PATH, STOP_WORD_PATH); vector<string> words; vector<cppjieba::Word> jiebawords; string s = ch0; string result; jieba.Cut(s, words, true); ofstream file("result.txt"); file << limonp::Join(words.begin(), words.end(), "/") << endl; file.close(); return 0; };
您好啊,如果输入是“我爱吃苹果”,还是会报错?
通过CMake生成VS2019工程,存在的问题: