On Thu, 27 Mar 2008 05:12:14 -0700, Ali wrote:
I would like to write a program that can handle non-ANSI characters. The
following code does not work, the output is empty:
#include <fstream>
#include <string>
using namespace std;
int main() {
wofstream out(L"log");
if (!out)
exit(127);
wstring s(L"őű*ŐŰÍ");
out << s << endl;
out.close();
return 0;
}
The log file is in ANSI char encoding, and probably that is why the
output fails.
Could anyone help me how to do this?
Remember that everything "wide" is not automatically unicode.
Try saving the source file in utf-8 and open ordinary non-wide
streams and output the string. Then you need to open the log
file with a program that understands utf-8 and can display the
actual characters.
The following outputs correctly on my terminal when I save the
source file as utf-8:
#include <iostream>
int main() {
std::cout << "őű*ŐŰÍ" << std::endl;
return 0;
}
--
Tobias Blomkvist
http://www.tobiasblomkvist.se/tobiasland