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

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() )
		{
     			getline(myfile,line);
			wcout << line << endl;
 		}

    		myfile.close();
 	 }

	return 0;
}

Writing unicode files should be self-explanatory.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.