By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,810 Members | 783 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,810 IT Pros & Developers. It's quick & easy.

Why does this work?!?

P: n/a
I thought system("PAUSE"); was part of stdlib.h and cstdlib. Then why does
this work? :

#include <iostream>
using namespace std;
int main()
{
cout << "hello, world" << endl;
system("PAUSE");
return 0;
}

It seems that system is part of iostream?!? that's news to me!
Jul 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Tue, 9 Dec 2003 23:38:43 -0500, "Mark Bruno"
<br*********@comcast.net> wrote in comp.lang.c++:
I thought system("PAUSE"); was part of stdlib.h and cstdlib. Then why does
this work? :

#include <iostream>
using namespace std;
int main()
{
cout << "hello, world" << endl;
system("PAUSE");
return 0;
}

It seems that system is part of iostream?!? that's news to me!


Just one of the quiet changes in C++ from C. The C language standard
specifically prohibits any standard header from including any other
standard header. The C++ language standard, OTOH, specifically allows
ANY standard header to include any or all other standard headers at
the discretion of the implementors. So <iostream> including <cstdlib>
or <stdlib.h> is perfectly legal behavior for your compiler.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Jul 22 '05 #2

P: n/a
"Mark Bruno" <br*********@comcast.net> wrote in message
news:Hf********************@comcast.com
I thought system("PAUSE"); was part of stdlib.h and cstdlib. Then
why does this work? :

#include <iostream>
using namespace std;
int main()
{
cout << "hello, world" << endl;
system("PAUSE");
return 0;
}

It seems that system is part of iostream?!? that's news to me!


This may vary from one system to another, but on VC++ 7.0:

iostream includes istream
istream include ostream
ostream includes ios
ios includes xlocnum
xlocnum includes cstdlib
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)
Jul 22 '05 #3

P: n/a

"Mark Bruno" <br*********@comcast.net> wrote in message
news:Hf********************@comcast.com...
I thought system("PAUSE"); was part of stdlib.h and cstdlib. Then why does this work? :

#include <iostream>
using namespace std;
int main()
{
cout << "hello, world" << endl;
system("PAUSE");
return 0;
}

It seems that system is part of iostream?!? that's news to me!


try tracing the #includes from <iostream>
Jul 22 '05 #4

P: n/a
Thanks guys, you explained it perfectly. I guess I should always add
#include <cstdlib> in such a scenario for compiler compatibility?
Jul 22 '05 #5

P: n/a
"Mark Bruno" <br*********@comcast.net> wrote in message
news:f6********************@comcast.com
Thanks guys, you explained it perfectly. I guess I should always add
#include <cstdlib> in such a scenario for compiler compatibility?


In order to guarantee that system will be declared, yes.
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)
Jul 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.