Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problems with std::ofstream function on std::ios::binary parameter

Problems with std::ofstream function on std::ios::binary parameter

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++iosquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    josip cagalj
    wrote on last edited by
    #1

    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

    C S 2 Replies Last reply
    0
    • J josip cagalj

      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

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      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++

      J 1 Reply Last reply
      0
      • C Cedric Moonen

        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++

        J Offline
        J Offline
        josip cagalj
        wrote on last edited by
        #3

        Thanks! That's it.

        J 1 Reply Last reply
        0
        • J josip cagalj

          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

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          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 support

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          J 1 Reply Last reply
          0
          • J josip cagalj

            Thanks! That's it.

            J Offline
            J Offline
            josip cagalj
            wrote on last edited by
            #5

            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

            S 1 Reply Last reply
            0
            • S Stuart Dootson

              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 support

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

              J Offline
              J Offline
              josip cagalj
              wrote on last edited by
              #6

              Thanks to you also. Please see my new post.

              1 Reply Last reply
              0
              • J josip cagalj

                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

                S Offline
                S Offline
                Stuart Dootson
                wrote on last edited by
                #7

                Check 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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups