473,387 Members | 3,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

using reinterpret_cast

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.


Jul 23 '05 #1
2 1709
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
Jul 23 '05 #2
thx a lot, that helps.. lol, yep, thx again

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:tu********************@comcast.com...
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

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Suzanne Vogel | last post by:
I'd like to convert a double to a binary representation. I can use the "&" bit operation with a bit mask to convert *non* float types to binary representations, but I can't use "&" on doubles. ...
25
by: rokia | last post by:
in a project, I use many,many stl such as stack,list,vctor etc. somewhere the vector's size is more than 2K. is this a efficient way?
5
by: Christopher Benson-Manica | last post by:
enum foo {a,b,c,d}; int main() { unsigned int bar=reinterpret_cast< unsigned int >( a ); return bar; } g++ rejects the code based on the reinterpret_cast, so I presume it is not legal. ...
13
by: Jakob Bieling | last post by:
Hi, I am trying to determine the endianness of the system as follows: int i = 1; bool is_little = *reinterpret_cast <char*> (&i) != 0; But now I was asking myself, if this use of...
1
by: Bern McCarty | last post by:
I am using MEC++ in VC 7.1. I had a method on a __gc object that looked like this: __property System::UInt32 get_MyProperty(void) { System::Byte __pin * pinBytes = &m_byteArray; // entire...
2
by: Taran | last post by:
Hi All, I was trying some code which essentially does what the function 'func' here does. To simplify the things and make a consise post I have created a dummy app to show my problem. The issue...
7
by: Peter | last post by:
I never used reinterpret_cast -- probably because I don't know what it means. Can somebody enlighten me? I looked into Stroustrup's "The annoted C++ reference manual" -- but this was no help....
2
by: Lucy Ludmiller | last post by:
I have two classes: class base { ... }; and class derived : public base { ... }; I have a function :
4
by: tkirankumar | last post by:
Hi all, This is regarding the issue I am facing while porting the my application from SuSe Linux to Sun Solaris. The Existing system details: Itanium boxes 1mhz 4 processor 8 gb machines with...
27
by: Noah Roberts | last post by:
What steps do people take to make sure that when dealing with C API callback functions that you do the appropriate reinterpret_cast<>? For instance, today I ran into a situation in which the wrong...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.