problem with std::wofstream [modified]
-
Hi I am having some problem with writing binary data using std::wofstream. I am using following code to write a double number but nothing is being written to the file. Am I doing something wrong? I am compling using UNICODE defined and wchar_t is defined as an internal type.
#include <iostream>
#include <fstream>
#include <math.h>int _tmain(int argc, _TCHAR* argv[])
{
std::wofstream fp("test.txt", std::ios::binary);double x = sqrt(2.0); fp.write(reinterpret\_cast<const wchar\_t\*>(&x), sizeof(x)); fp.close(); return 0;
}
-Saurabh -- modified at 0:28 Thursday 15th November, 2007
-
Hi I am having some problem with writing binary data using std::wofstream. I am using following code to write a double number but nothing is being written to the file. Am I doing something wrong? I am compling using UNICODE defined and wchar_t is defined as an internal type.
#include <iostream>
#include <fstream>
#include <math.h>int _tmain(int argc, _TCHAR* argv[])
{
std::wofstream fp("test.txt", std::ios::binary);double x = sqrt(2.0); fp.write(reinterpret\_cast<const wchar\_t\*>(&x), sizeof(x)); fp.close(); return 0;
}
-Saurabh -- modified at 0:28 Thursday 15th November, 2007
Just a question, with that std::wofstream, is it not needed to specify that you create the file to Write or to Read? I mean, you are saying that is binary, but you don't say you want to write to it. With CFile you must say it.
Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson ;)
-
Just a question, with that std::wofstream, is it not needed to specify that you create the file to Write or to Read? I mean, you are saying that is binary, but you don't say you want to write to it. With CFile you must say it.
Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson ;)
ofstream is output file stream and wofstream is output file stream for wide characters. For input there are ifstream and wifstream. -Saurabh