Problems with wofstream (no output)
Neil Bird
neil@fnxweb.com
Wed Jan 11 13:03:00 GMT 2006
Not actually sure that this is specifically libstdc++, or gcc or even just
my understanding!
I'm stumbling around a little bit here trying to get a feel for
wide/Unicode functionality. I'm pretty up on C++ in general, streaming stuff
not so much.
If I run the following code, I get a zero length file. If I take out
*both* string outputs, I get '123abc' as expected. 'Last error' is always 0,
I get none of the debug error output.
Am I doing something wrong/obviously stupid? g++ 3.4.4 on Linux.
#include <iostream>
#include <fstream>
#include <errno.h>
int main()
{
std::string jobby = "Hello \u201Cwotsit\u201D\n";
std::wstring wjobby = L"Hello \u201Cwotsit\u201D\n";
std::wofstream file("jobby.out");
if (!file.good()) std::cerr << "Open error\n";
file << 123;
if (!file.good()) std::cerr << "Write error 1\n";
file << "abc";
if (!file.good()) std::cerr << "Write error 2\n";
file << jobby.c_str() << " normal char 10 is '" << jobby[10] << "'\n";
if (!file.good()) std::cerr << "Write error 3\n";
file << wjobby << L" wide char 10 is '" << wjobby[10] << L"'\n";
if (!file.good()) std::cerr << "Write error 4\n";
file.close();
std::cerr << "\nLast error " << errno << "\n";
return 0;
}
--
[neil@fnx ~]# rm -f .signature
[neil@fnx ~]# ls -l .signature
ls: .signature: No such file or directory
[neil@fnx ~]# exit
More information about the Libstdc++
mailing list