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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. problem with std::wofstream [modified]

problem with std::wofstream [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
ioshelpquestion
3 Posts 2 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.
  • S Offline
    S Offline
    Saurabh Garg
    wrote on last edited by
    #1

    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

    N 1 Reply Last reply
    0
    • S Saurabh Garg

      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

      N Offline
      N Offline
      Nelek
      wrote on last edited by
      #2

      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 ;)

      S 1 Reply Last reply
      0
      • N Nelek

        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 ;)

        S Offline
        S Offline
        Saurabh Garg
        wrote on last edited by
        #3

        ofstream is output file stream and wofstream is output file stream for wide characters. For input there are ifstream and wifstream. -Saurabh

        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