using reinterpret_cast

Discussion in 'C++' started by Someonekicked, May 2, 2005.

  1. here is a part of the program thats not working:

    -----------------------------------------------------------
    #include <iostream>

    #include <fstream>

    using namespace std;

    int main ()

    {

    int current = 8526336;

    ofstream outTemp("primes_temp.txt", ios::binary);

    outTemp.write( reinterpret_cast<const char *>(&current), sizeof(int) );

    outTemp.close();

    ifstream inTemp("primes_temp.txt");

    current = 0;

    inTemp.read(reinterpret_cast<char *>(&current), sizeof(int));

    cout << current << endl;

    return 0;

    }



    -----------------------------------------------------------



    ok, if i change 8526336 to 8526334, or another number, program works fine,
    and i will get that number as output, but whats so special about 8526336?

    why i dont get an answer?

    thx in advance for any help or suggestions.
     
    Someonekicked, May 2, 2005
    #1
    1. Advertising

  2. Someonekicked wrote:
    > here is a part of the program thats not working:
    >
    > -----------------------------------------------------------
    > ofstream outTemp("primes_temp.txt", ios::binary);
    > ifstream inTemp("primes_temp.txt");


    So, why are you open it for writing as 'ios::binary' but do not use
    the same flag when opening it for reading?

    I will leave it to you to investigate the difference.

    V
     
    Victor Bazarov, May 2, 2005
    #2
    1. Advertising

  3. thx a lot, that helps.. lol, yep, thx again



    "Victor Bazarov" <> wrote in message
    news:...
    > Someonekicked wrote:
    >> here is a part of the program thats not working:
    >>
    >> -----------------------------------------------------------
    >> ofstream outTemp("primes_temp.txt", ios::binary);
    >> ifstream inTemp("primes_temp.txt");

    >
    > So, why are you open it for writing as 'ios::binary' but do not use
    > the same flag when opening it for reading?
    >
    > I will leave it to you to investigate the difference.
    >
    > V
    >
     
    Someonekicked, May 2, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Suzanne Vogel
    Replies:
    17
    Views:
    814
    Suzanne Vogel
    Jul 7, 2003
  2. Scott Brady Drummonds

    reinterpret_cast<>() v. static_cast<>()

    Scott Brady Drummonds, Jan 13, 2004, in forum: C++
    Replies:
    11
    Views:
    20,722
    Nick Hounsome
    Jan 20, 2004
  3. Aman

    reinterpret_cast<>

    Aman, Feb 23, 2004, in forum: C++
    Replies:
    15
    Views:
    849
    Ben Hutchings
    Feb 25, 2004
  4. Replies:
    0
    Views:
    348
  5. Alex Vinokur
    Replies:
    1
    Views:
    582
Loading...

Share This Page