Writing unicode characters to text file

L

Lex Syntax

Hi,

I wanted to write a unicode character, e.g \u1200, to a text file.
Tried this but doesn't work:

int main(int argc, char* argv[])
{
std::eek:fstream out("d:\\test.txt");
out << "\u1200";
out.close();
return 0;
}

Any ideas?
 
J

Juha Nieminen

Lex Syntax said:
I wanted to write a unicode character, e.g \u1200, to a text file.
Tried this but doesn't work:

What do you mean "it doesn't work"? What is it exactly that you want to
do. "Write a unicode character to a file" is not enough description to
know what is it that you want.

Unicode defines numerical values for characters. It doesn't define how
those values are stored. There are ancillary standards that define how
those values should be stored. Several ones. Most typical examples include
the UTF-8 and the UTF-16 formats. (In theory you could also store them
raw, which I suppose would be something akin to UTF-32, but even then
you have the problem of specifying endianess.)

If you want to store the unicode character eg. in UTF-8 format, you
have to convert it. There's (currently) no functionality in standard C++
to do this conversion, but you can use a third-party library such as
http://utfcpp.sourceforge.net/
 
L

Lex Syntax

  What do you mean "it doesn't work"? What is it exactly that you want to
do. "Write a unicode character to a file" is not enough description to
know what is it that you want.

  Unicode defines numerical values for characters. It doesn't define how
those values are stored. There are ancillary standards that define how
those values should be stored. Several ones. Most typical examples include
the UTF-8 and the UTF-16 formats. (In theory you could also store them
raw, which I suppose would be something akin to UTF-32, but even then
you have the problem of specifying endianess.)

  If you want to store the unicode character eg. in UTF-8 format, you
have to convert it. There's (currently) no functionality in standard C++
to do this conversion, but you can use a third-party library such ashttp://utfcpp.sourceforge.net/

Thanks for the explanation and the url.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top