exit() problem

i run the codes as follow:
1
2
3
4
5
if(length != np*sizeof(float)*6)
{
cout<<"The size of file "<<_lname.front()<<" is not right!"<< endl;
exit(EXIT_FAILURE);
}

but it does not show the message properly.

But if I ran as follow:
1
2
3
4
5
if(length != np*sizeof(float)*6)
{
cout<<"The size of file "<<_lname.front()<<" is not right!";
exit(EXIT_FAILURE);
}

it will show the message properly. I don't understand why does it happen.
closed account (S6k9GNh0)
It's not a problem with exit. It's a matter of the stream not flushing which means its still in pending. Using std::flush instead of std::endl will give a similar and proper result.
but I think endl is "\n"+flush. why it doesn't work?
I also tried <<flush. it also doesn't work. the message only show half.
You should post a compilable minimal example that exhibits the problem.
And what is shown exactly anyway?
I'm skeptical. Take Athar's advice and compile a small test program to verify that it works.

Are you sure it doesn't have to do with _lname.front()? Is it a string? Is it null terminated? This sounds like a memory issue.

Also, what on Earth are you doing here?
if(length != np*sizeof(float)*6)
Last edited on
The file is quite big. I think the problem is quite easy to explain:
if I try
 
cout<<"The size of file "<<_lname.front()<<" is not right!"<<endl;

before exit(FAILURE) or retrun false; in Linux. Everything is alright.

But if I run it in MSVC 2008, sometime it can only show "The size of file " without the rest.
if I try
1
2
cout<<"The size of file "<<_lname.front()<<" is not right!"<<endl<<endl;
exit(FAILURE);
in MSVC. the result is alright.
if I try
1
2
cout<<"The size of file "<<_lname.front()<<" is not right!"<<endl;
//exit(FAILURE); 
the message shows correctly.
I think it's a problem of endl and exit function were put together in MSVC.
And if I try
1
2
cout<<"The size of file "<<_lname.front()<<" is not right!\n";
exit(FAILURE);
the message is alright.
Well, the problem is not with the code you posted, but somewhere else (invalid memory accesses or whatnot). Then again, hard to tell without even knowing what _lname is.
_lname is a list<string> which store many binary files' names
I add one file with wrong size to the list, so when the searching reach this file, the codes will execute these two lines.
Topic archived. No new replies allowed.