public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* wfstream help
@ 2004-07-19 14:26 Bernd Prager
  0 siblings, 0 replies; only message in thread
From: Bernd Prager @ 2004-07-19 14:26 UTC (permalink / raw)
  To: gcc-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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-07-19 14:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-19 14:26 wfstream help Bernd Prager

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).