OPENCC Traditional Simplified Mutual transfer (C + + example)

Source: Internet
Author: User

Traditional Chinese characters usually use BIG5 encoding, simplified characters are usually used GBK or GB18030 encoding, in this case, the direct use of Iconv (Linux under the corresponding command, there is a corresponding C API for programming calls) on the line. Iconv is not a way to use the default Utf-8 encoded file or the case where it is common to use utf-8. Here we can use a call OPENCC Open Source Library, to achieve the UTF-8 encoding environment of the simplified, traditional mutual transfer function. To complete the installation of the OPENCC Library with reference to Https://github.com/BYVoid/OpenCC the following are the features of the traditional-to-simplified program that you use to invoke the relevant APIs in C + + programs
Test.cpp #include <iostream> #include <opencc/opencc.h> using namespace std; int main (int argc, char *argv[]) {    string str= "anti-secession family laws of the People's Republic of China";    String str= "anti-secession law of the People's Republic of China";     The default is simplified to traditional that is Opencc_default_config_trad_to_simp, opencc.h header file is described in detail    opencc_t ot = Opencc_open (opencc_default_ CONFIG_TRAD_TO_SIMP);     Char buffer[512] = {'} '};    Opencc_convert_utf8_to_buffer (OT, Str.c_str (), str.size (), buffer);    cout << "result is" << buffer << Endl;     Opencc_close (OT);     return 0;}

Compile g++ test.cpp-o TEST-LOPENCC

OPENCC Traditional Simplified Mutual transfer (C + + example)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.