Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS2019工程问题 #142

Open
playgithub opened this issue Mar 14, 2020 · 3 comments
Open

VS2019工程问题 #142

playgithub opened this issue Mar 14, 2020 · 3 comments

Comments

@playgithub
Copy link

playgithub commented Mar 14, 2020

通过CMake生成VS2019工程,存在的问题:

  1. VS2019需要UTF8 BOM格式,UTF8不能正确识别中文
  2. demo的working directory不对,导致找不到../dict/jieba.dict.utf8
    目录结构:
    Root
    VS2019 solution folder
    cppjieba source folder
  3. 修改demo工程文件编码和working directory后运行,显示乱码
@kilasuelika
Copy link

在VS2019上实验成功了。

  1. 不需要编译,直接把include和deps文件夹复制到项目中,然后在VS的include中添加。所以不要管demo。
  2. 源代码文件用UTF8编码(VS中新建时默认是936,可以用notepad++转换成UTF8)。分词结果用ofstream输出到文件再打开,不要输出到控制台,否则显示乱码。
  3. 如果使用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;
};

@playgithub
Copy link
Author

  1. 不需要编译,直接把include和deps文件夹复制到项目中,然后在VS的include中添加。所以不要管demo。

  1. 源代码文件用UTF8编码(VS中新建时默认是936,可以用notepad++转换成UTF8)。分词结果用ofstream输出到文件再打开,不要输出到控制台,否则显示乱码。

  1. 如果使用C++20标准,那么limonp的StringUtils.hpp需要修改,因为not1和bind2nd几个函数在新标准中remove了。

是的,C++17也要改

@zhengshuo1
Copy link

在VS2019上实验成功了。

  1. 不需要编译,直接把include和deps文件夹复制到项目中,然后在VS的include中添加。所以不要管demo。
  2. 源代码文件用UTF8编码(VS中新建时默认是936,可以用notepad++转换成UTF8)。分词结果用ofstream输出到文件再打开,不要输出到控制台,否则显示乱码。
  3. 如果使用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;
};

您好啊,如果输入是“我爱吃苹果”,还是会报错?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants