Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I cin and cout some unicode text?

I ask a code snippet which cin a unicode text, concatenates another unicode one to the first unicode text and the cout the result.

P.S. This code will help me to solve another bigger problem with unicode. But before the key thing is to accomplish what I ask.

ADDED: BTW I can't write in the command line any unicode symbol when I run the executable file. How I should do that?

like image 787
Narek Avatar asked Jul 08 '10 20:07

Narek


People also ask

Can we convert Unicode to text?

Unicode text normalizer tool What is a unicode text normalizer? This online web application normalizes Unicode text. It converts all typographic Unicode glyphs to readable English characters from the ASCII charset.

How do I create a Unicode text file?

Go to File -> Save As -> in the drop down menu just below the file name field change the file type from Unicode Text Document to Text Document. Now enter the file name you want remembering to specify the suffix you want such as .

What is a Unicode text format?

Unicode is a standard encoding system that is used to represent characters from almost all languages. Every Unicode character is encoded using a unique integer code point between 0 and 0x10FFFF . A Unicode string is a sequence of zero or more code points.


1 Answers

I had a similar problem in the past, in my case imbue and sync_with_stdio did the trick. Try this:

#include <iostream>
#include <locale>
#include <string>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    wcin.imbue(locale("en_US.UTF-8"));
    wcout.imbue(locale("en_US.UTF-8"));

    wstring s;
    wstring t(L" la Polynésie française");

    wcin >> s;
    wcout << s << t << endl;
    return 0;
}
like image 106
Bolo Avatar answered Oct 20 '22 21:10

Bolo