2

I was use the protobuf to read and write config file. but I found the chinese character can't correctly write to the file.

the encode code:

zrd::Config cfg;
zrd::Market *market = nullptr;
market = cfg.add_market();
market->set_id("11");
market->set_name("清江冷链市场");
market->set_district("六合区");

string content;
google::protobuf::TextFormat::PrintToString(cfg, &content);

when run finished , the content is like this:

market {\n id: \"11\"\n name: \"\346\270\205\346\261\237\345\206\267\351\223\276\345\270\202\345\234\272\"\n district: \"\345\205\255\345\220\210\345\214\272\"\n}

why the chinese character is convert to that way ? when I use ofstream to write the content to file, such chinese characters are not convenient to read. but the probobuf can decode it successfully.

I wonder know whether there is way to save the chinese characters in right way?

0 Answers0