problem with wifstream

de Chalendar Gael DE-CHALENDARG@zoe.cea.fr
Thu Oct 3 08:31:00 GMT 2002


Hello,

I have a problem using wide characters file streams. There is really few
non-reference occurrences of this class name in the web and so I ask
here.

A "normal" version of the program works while the one using wide
characters does not work.
I don't know if is an error from me or a bug...

The files pasted below explain the problem. I showed the test file and
the two versions of the program with their results. I show also my
version of gcc.

Note that I am able to use the wstring and wstream classes when putting
wide characters strings directly inside the code. The problem appears
only with file reading.

Thanks in advance for your help.

______________
TEST txt file (a less of a windows1252 txt file)
ÞÇá ÇáÑÆíÓ ÇáÃãíÑßí ÌæÑÌ ÈæÔ Åä ÇáÈäÏ 214 ÇáãÊÚáÞ ÈÇáÞÏÓ Ýí ÞÇäæä
ÇáÚáÇÞÇÊ ÇáÎÇÑ
ÌíÉ ÇáÌÏíÏ ÇáÐí æÞÚå ÃãÓ "íÊÚÇÑÖ ÈØÑíÞÉ ÛíÑ ãÞÈæáÉ ãÚ ÓáØÇÊ ÇáÑÆíÓ
ÇáÏÓÊæÑíÉ ÈÔÃ
ä ÇáÓíÇÓÉ ÇáÎÇÑÌíÉ ááÃãÉ æÇáÅÔÑÇÝ Úáì ÇáÔÞ ÇáÊäÝíÐí"¡ æÃßÏ Ãä ÓíÇÓÉ
ÈáÇÏå ÈÔÃä Ç
áÞÏÓ áã ÊÊÛíÑ ÑÛã ÊæÞíÚå Úáì ÇáÞÇäæä ÇáãÔÇÑ Åáíå.

______________
TEST PROGRAM WITH ifstream
#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char *argv[])
{
	ifstream filefr;
	filefr.open("test.txt", ifstream::in );
	if (filefr) cout << "OK " << filefr.rdbuf() <<endl;
	else cerr << "ERROR" <<endl;
}

______________
RESULT with ifstream
OK ÞÇá ÇáÑÆíÓ ÇáÃãíÑßí ÌæÑÌ ÈæÔ Åä ÇáÈäÏ......

______________
TEST PROGRAM WITH wifstream
#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char *argv[])
{
	wifstream filefr;
	filefr.open("test.txt", wifstream::in );
	if (filefr) wcout << "OK " << filefr.rdbuf() <<endl;
	else wcerr << "ERROR" <<endl;
}

______________
RESULT with wifstream
OK 
[Nothing printed after that !!]

______________
MY GCC VERSION
gcc -v
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.2/specs
Configured with: ../configure --prefix=/usr --libdir=/usr/lib
--with-slibdir=/lib --mandir=/usr/share/man --infodir=/usr/share/info
--enable-shared --enable-threads=posix --disable-checking
--enable-long-long --enable-__cxa_atexit
--enable-languages=c,c++,ada,f77,objc,java
--host=i586-mandrake-linux-gnu --with-system-zlib
Thread model: posix
gcc version 3.2 (Mandrake Linux 9.0 3.2-1mdk)




More information about the Gcc-help mailing list