using reinterpret_cast

S

Someonekicked

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.
 
V

Victor Bazarov

Someonekicked said:
here is a part of the program thats not working:

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
 
S

Someonekicked

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



Victor Bazarov said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top