Problems with std::ofstream function on std::ios::binary parameter
-
Hi, in my app I have the following code:
std::ofstream f(sPath.GetBuffer(0), std::ios::binary); f.write((const char \*) pBytes, dwSize); f.close();
I also include 'iostream.h'
#include
I'm getting error: -error C2027: use of undefined type 'basic_ios<char,struct> >' -error C2065: 'binary' : undeclared identifier -error C2079: 'f' uses undefined class 'basic_ofstream<char,struct> >' -error C2078: too many initializers -error C2228: left of '.write' must have class/struct/union type -error C2228: left of '.close' must have class/struct/union type Help? Thanks! P.S. Using vc++ 6 on WinXP SP3 -
Hi, in my app I have the following code:
std::ofstream f(sPath.GetBuffer(0), std::ios::binary); f.write((const char \*) pBytes, dwSize); f.close();
I also include 'iostream.h'
#include
I'm getting error: -error C2027: use of undefined type 'basic_ios<char,struct> >' -error C2065: 'binary' : undeclared identifier -error C2079: 'f' uses undefined class 'basic_ofstream<char,struct> >' -error C2078: too many initializers -error C2228: left of '.write' must have class/struct/union type -error C2228: left of '.close' must have class/struct/union type Help? Thanks! P.S. Using vc++ 6 on WinXP SP3josip cagalj wrote:
I also include 'iostream.h'
You should include <fstream> also. And iostream.h is deprecated, you should include <iostream> instead (without the .h).
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
josip cagalj wrote:
I also include 'iostream.h'
You should include <fstream> also. And iostream.h is deprecated, you should include <iostream> instead (without the .h).
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++Thanks! That's it.
-
Hi, in my app I have the following code:
std::ofstream f(sPath.GetBuffer(0), std::ios::binary); f.write((const char \*) pBytes, dwSize); f.close();
I also include 'iostream.h'
#include
I'm getting error: -error C2027: use of undefined type 'basic_ios<char,struct> >' -error C2065: 'binary' : undeclared identifier -error C2079: 'f' uses undefined class 'basic_ofstream<char,struct> >' -error C2078: too many initializers -error C2228: left of '.write' must have class/struct/union type -error C2228: left of '.close' must have class/struct/union type Help? Thanks! P.S. Using vc++ 6 on WinXP SP3josip cagalj wrote:
I also include 'iostream.h'
As well as adding in
#include <fstream>
, let's change that#include <iostream.h>
to#include <iostream>
- that's what you should be including for standard stream supportJava, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Thanks! That's it.
Still one thing more, how to test why std::ofstream failed. My code:
std::ofstream f(sPath.GetBuffer(0), std::ios::binary);
fails to open file, I test that with
f.is_open()
, but why? Thanks -
josip cagalj wrote:
I also include 'iostream.h'
As well as adding in
#include <fstream>
, let's change that#include <iostream.h>
to#include <iostream>
- that's what you should be including for standard stream supportJava, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Thanks to you also. Please see my new post.
-
Still one thing more, how to test why std::ofstream failed. My code:
std::ofstream f(sPath.GetBuffer(0), std::ios::binary);
fails to open file, I test that with
f.is_open()
, but why? ThanksCheck the path you're supplying to the
ofstream
constructor - this little C++ program works for me, which demonstrates the library doing the right thing:#include <iostream>
#include <fstream>int main(int, char**)
{
std::ofstream f("a.a", std::ios::binary);
if (!f.is_open())
{
std::cerr << "File open failed" << std::endl;
}
else
{
f << "Hello";
f.close();
}
}Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p