wfstream help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux