why C++ sudenly stop working ?


this is no error, it start to run until hit output function:

1
2
3
void fout ()
{   myfile << Rtime << '\t' << velocity << '\n';
} 


running stops and Microsoft Window pop up with message:

microsoft c ++ stop working. you can

debug online
close the program
....

I am using stringstream to open a output file, write data in, and close it.
I have similar output function to write title into the same output file by 'myfile'. it has no problem.
I also delete the massive calculations in code to simplify this C code. it turns out work. but when I add computation back. it stop.

please help
Last edited on
That doesn't even look like legal code. I'm surprised it compiles...
typooooo , sorry

1
2
3
void fout ()
{   myfile << Rtime[t] << '\t' << velocity[t] << '\n';
} 


in which, myfile has been declared globally and Rtime, velocity has been calculated as a long array

Maybe some more code will help diagnose, you mentioned you do this in another function, are you opening and closing the file there as well? Is fout() only called if the file has been successfully opened?

long Rtime[someNumber] //Is this how Rtime is defined? same for velocity?

I am using stringstream to open a output file
Do you mean you are using a stringstreams str() function with c_str() to convert to const char * to open the file?
thanks, clanmjc

my situation is too complicated. I defined Rtime/ velocity by
double Rtime[6000], velocity[6000];

there is really no error. I don't even know where is the problem make it stop.
the only thing I know is that it stop running at this fout () function.
but when I delete some computation code. it works again.

I have 'myfile' defined globally before main() function:
stringstream myfile;
Last edited on
closed account (zb0S216C)
When a program suddenly stops working, it can mean 1 of 2 things:

1) You've attempted to access memory that doesn't belong to you.
2) You've attempted to dereference a null pointer.

ppcandy wrote:
myfile << Rtime[t] << '\t' << velocity[t] << '\n';

Of what value is t? What's its range?

Wazzak
Topic archived. No new replies allowed.