This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

wfstream help


Hi all,
I'm trying to read a file that contains UTF-8 encoded characters.
I can't find sufficient information how to implement wfstream poperly.
I'm using g++ (GCC) 3.4.0.  Here's my short test file:

#include <iostream>
#include <fstream>
 
using namespace std;
typedef basic_fstream<wchar_t> wfstream;
 
int main()
{	// internal read buffer
	wchar_t buffer[255];
	
	// read the ini file
	wfstream file("tst.txt");
	if (!file.is_open()) {
		cerr << "can't open file " << endl;
	}
	file.getline(buffer, sizeof(buffer));
	
	cout << buffer << endl;
	// close the file
	file.close();
	return (0);
}

First I was confused that I had to insert the typedef for wfstream or I
get: "error: `wfstream' undeclared"
(I thought that would be already a standard feature?)
But even the program compiles now without warnings its crashes
during execution with:

terminate called after throwing an instance of 'std::bad_cast'
  what():  St8bad_cast
Aborted (core dumped)

Can anybody tell me what I'm doing wrong?
Thanks,
-- Bernd


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]