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)