I'm trying to read a Unicode file using std::wifstream. On wintel.

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
	wifstream File("input.txt");
	wstring Line;

	while(!File.eof() )
	{
		getline(File, Line);

		wcout << Line << endl;
	}
	system("pause");
	return 0;
}

And this is my output

 ■A   s e q u e n c e   o f   l e x i c o n s   t h a t   m a k e   u p   a   s
e n t e n c e .
Press any key to continue . . .

Now the spaces between each character and the '■' thing at the start arn't in the text file. What am I doing wrong?

The "thing" at the start is probably a binary character that tells programs the file is UNICODE format -- its called "UNICODE signature". When you click this link scroll down the page until you find the section titled "unicode signature". Please feel free to read the rest of the page too :)

I'm trying to read a Unicode file using std::wifstream. On wintel.

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
	wifstream File("input.txt");
	wstring Line;

	while(!File.eof() )
	{
		getline(File, Line);

		wcout << Line << endl;
	}
	system("pause");
	return 0;
}

And this is my output

 ■A   s e q u e n c e   o f   l e x i c o n s   t h a t   m a k e   u p   a   s
e n t e n c e .
Press any key to continue . . .

Now the spaces between each character and the '■' thing at the start arn't in the text file. What am I doing wrong?

Well, at first blush (I haven't tested it) you may need to specify

getline<wchar_t>( File, Line );

Hope it helps,
Sean

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.