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-example.html

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 <frederic.bron@m4x.org>
To: boost-users <boost-users@lists.boost.org>
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 <boost/locale/encoding.hpp>

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<wchar_t>(line, "UTF-8",
boost::locale::conv::stop);
                                std::wcout<<ws;
                        }
                        catch (...) {
                                std::cout<<"exception\n";
                        }
                }
        }
        is.close();
        return 0;
}

Frédéric
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users