Can someone please help me to understand how to read and write unicode from/to a file? also how to set and print a variable to/with unicode (like a wchar_t variable or whatever.)?
Im at an intermeddiate lvl in C++, and when I search this on google I don't understand a lot of the code on websites and stuff. (By the way I use int main() way more than int void() or anything that have to do with void...). Thanks!

P.S The purpose is for making a chinese program. Im an american person, but im taking chinese classes in school and I know a lot of it.

visit http://www.live-chinese-translations.synthasite.com
visit http://www.programming-wizard.synthasite.com

8 Years
Discussion Span
Last Post by NekoGráfico

Please don't use such vibrant colors... lol.
Haven't tested the code but I think this should work...

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
	ifstream myfile("example.txt");
	wstring line;

	if (myfile.is_open())
		while (! myfile.eof() )
			wcout << line << endl;


	return 0;

Writing unicode files should be self-explanatory.


Thanks for clearing that out! I didn't notice the use of typical streams.

Use std::wifstream, std::wofstream and other w..streams - streams of wchar_t elements.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.