C++ has code facets which make it possible to read UTF8 or another text encoding into the wstring containers. I couldn’t find much information on how to implement the facet or any sample code apart a utf-8 facet implementation in the Boost libraries.
The below minimal sample will read from a text file (named utf8.txt). For example if the text file utf8.txt contains a single line with the text “日本語”. When reading using standard streams the utf8 is treated a streams of bytes and report a longer length of 9. When reading the stream the
To print the string or individual utf8 chars will require converted back to utf-8 or terminal that support UTF16/32 (nw UCS-16/32??)
Tested on Windows and Linux. The Fedora boost package didn’t include the utf8_codecvt_facet.cpp file. The file can be obtained here
#include <iostream>
#include <fstream>
#include <locale>
#define BOOST_UTF8_BEGIN_NAMESPACE
#define BOOST_UTF8_END_NAMESPACE
#define BOOST_UTF8_DECL
#include <boost/detail/utf8_codecvt_facet.hpp>
//This file wasn't present in Fedora boost package
// but was under Windows
//#include <libs/detail/utf8_codecvt_facet.cpp>
#include "utf8_codecvt_facet.cpp"
int main(int argc, char** argv)
{
std::wifstream wifs("utf8.txt");
wifs.imbue(std::locale(std::locale(), new utf8_codecvt_facet));
std::wstring wstr;
wifs >> wstr;
wifs.close();
std::cout << "wstr.length()=" << wstr.length() << std::endl;
std::ifstream ifs("utf8.txt");
std::string str;
ifs >> str;
std::cout << "str.length()=" << str.length() << std::endl;
ifs.close();
return 0;
}
coach outlet online
camisetas futbol baratas
herve leger dresses
louis vuitton neverfull sale
kate spade handbags
fitflops sale
oakley sunglasses
nike air huarache
ray ban sunglasses
football shirts
true religion jeans
timberland shoes
hermes birkin bag
rolex uk
fitflop clearance
cheap jordan shoes
louis vuitton bags cheap
mulberry outlet
mcm backpack
true religion jeans
nfl jerseys wholesale
fitflops clearance
air force 1 shoes
polo ralph lauren
air max 2015
louis vuitton handbags
nike huarache
christian louboutin online
oakley sunglasses
kobe bryants shoes
lebron james shoes
michael kors outlet online
cheap ray ban sunglasses
hermes belt
michael kors outlet online
20160415zhenhong
tory burch outlet
celine outlet
mulberry handbags
nike air force 1
christian louboutin outlet
mbt shoes
true religion jeans
polo ralph lauren
polo ralph lauren
thomas sabo uk
chanyuan10.15
cincinnati bengals jerseys stuffed
omega watches weekly
louis vuitton pas cher the
ghd hair straighteners out
nike trainers it
under armour shoes back
dallas cowboys jersey random
michael kors handbags wholesale obvious
true religion jeans sale could
toms outlet updating
ray ban glasses
oakley sunglasses cheap
rolex watches for sale
valentino shoes
puma outlet
true religion outlet store
coach outlet store online
hollister uk
coach outlet online
moncler pas cher
zhi20170103
ralph lauren polo
chaussures louboutin
hollister clothing
canada goose outlet
michael kors handbags
coach outlet
miami heat jerseys
polo ralph lauren
true religion outlet
ugg boots
20171.03wengdongdong