My program get an input chinese string in utf32 encoding:
./myprogram 我想玩
I want to convert this to utf8, for this I am using library UTF8-CPP http://utfcpp.sourceforge.net
#include "source/utf8.h"
using namespace std;
int main(int argc, char** argv)
{
printf("argv[1] = %s \n", argv[1]);
string str = argv[1];
printf("str = %s \n", str);
vector<unsigned char> utf8result;
utf8::utf32to8(str.begin(), str.end(), back_inserter(utf8result));
I got the next output in terminal:
argv[1] = 系
str = D�k�
terminate called after throwing an instance of 'utf8::invalid_code_point'
what(): Invalid code point
How to fix this code, so the conversation utf32to8 will be successfull? What am I doing wrong, please, explain me ? After that I want to write received utf8 to file.