This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
wfstream help
- From: bernd at prager dot ws (Bernd Prager)
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 19 Jul 2004 10:26:10 -0400
- Subject: wfstream help
- Reply-to: bernd at prager dot ws
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