odd C++ crash question with streams

L

laniik

Hi. What does it mean if my application is crashing on a cout<< line?
specifically:

cout<<"hello"<<endl

does not crash it, but

int i=0;
cout<<"hello"<<i<<endl;

does.

the crash is:

"unhandled exception at 0x00450460 in main.exe: 0xC0000005: Access
violation reading location 0x00000000"

Thanks!
 
A

Artie Gold

laniik said:
Hi. What does it mean if my application is crashing on a cout<< line?
specifically:

cout<<"hello"<<endl

does not crash it, but

int i=0;
cout<<"hello"<<i<<endl;

does.

the crash is:

"unhandled exception at 0x00450460 in main.exe: 0xC0000005: Access
violation reading location 0x00000000"

Thanks!
If you show us a minimal compilable program that exhibits this behavior,
someone here might be able to help you. Absent that, there's absolutely
no way to tell.

Cheers,
--ag
 
L

laniik

hmm, this is part of a larger program where its obviously somthing in
the code executed before this that is causing the problem. however i
cannot post the whole code, so i was hoping that someone might
recognize this error as being caused by something in specific that i
could look for in the code. but i agree, unless you've seen it before,
its not much to go on.
 
E

Evan

Are you dealing with pointers at all? Perhaps you have instead of i
being an int it's an int*, and you're doing << *i? If so, look to be
sure that i is properly initialized or set to whatever. It's trying to
read something at address 0, which is a Bad Thing(TM).

Other than that... I don't really have any idea.
 
L

laniik

i looked around and found that stuff like this with streams can happen
when the memory gets corrupted by accidental overwriting. this causes
the streams to be unable to allocate memory for the int in that line.

turns out i was writing a block of memory 2 bytes too large for the
allocated space. of course, this couldnt give me some kind of error at
that line, it has to manifest itself in some bizarre standard library
call.

hehe. i love c++

thanks for the help!
 

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,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top