
I read std::string from a file encoded in UTF-8.
I would like to sort the strings. I think I have to first convert them
to wide characters and then sort the resulting output.
I have tried to do that with boost::local::conv::to_utf(utf8string, "UTF-8");
But it seems that all non ASCII characters are replaced by the question mark.
Here is my program:
#include <iostream>
#include <fstream>
#include <string>
#include

First of all... http://www.boost.org/doc/libs/1_51_0/libs/locale/doc/html/collation.html And full example: http://www.boost.org/doc/libs/1_51_0/libs/locale/doc/html/collate_8cpp-examp... Notes: you don't need wide characters collation works on all strings Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/
________________________________ From: Frédéric Bron
To: boost-users Sent: Wednesday, January 9, 2013 12:07 PM Subject: [Boost-users] [locale] how to sort utf8 std::string? I read std::string from a file encoded in UTF-8. I would like to sort the strings. I think I have to first convert them to wide characters and then sort the resulting output. I have tried to do that with boost::local::conv::to_utf(utf8string, "UTF-8"); But it seems that all non ASCII characters are replaced by the question mark.
Here is my program: #include <iostream> #include <fstream> #include <string>
#include
int main(int argc, char **argv) { if (argc<2) return 0; std::ifstream is(argv[1], std::ios::binary); while (is) { std::string line; std::getline(is, line); if (not line.empty()) { try { std::wstring ws=boost::locale::conv::to_utf
(line, "UTF-8", boost::locale::conv::stop); std::wcout< Frédéric _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Incredible! No need to convert UTF8 std::string to wstring! Took me a while to understand how it works but it is very effective. Thanks! Frédéric
participants (2)
-
Artyom Beilis
-
Frédéric Bron