Normal C++ VS C++11

Jul 29, 2012 at 7:43am
Hi!
I program apps for windows but recently I've started developing for Mac OS X Mountain Lion using Xcode 4.4. But for some reason, it won't accept the most simple C++ app, Hello World!

Here's the code it gave me:

#include <iostream>

int main(int argc, const char * argv[])
{

// insert code here...
std::cout << "Hello, World!\n";
return 0;
}

Heres the code I wrote:

#include <iostream>

int main()
{
cout << "Hello, World!\n";
system ("pause");
return 0;
}


Thanks!
Jul 29, 2012 at 7:53am
You need to include cstdlib header to use system() function.
http://www.cplusplus.com/reference/clibrary/cstdlib/system/

However, it is not recommended to use it at all, anywoy sytem("pause") only do what you think in windows environment.
Jul 29, 2012 at 8:12am
Also you need to write using namespace std; in order to use cout.
PS: What does this have to do with C++ vs C++11?
Last edited on Jul 29, 2012 at 8:13am
Jul 29, 2012 at 10:31am
Sorry, I did writeusing namespace std; but forgot to mention it. When I was downloading Xcode in the description it said something like
Supports C++11.
Could you also just highlight some difference between C++ and C++11?
Last edited on Jul 29, 2012 at 10:33am
Jul 29, 2012 at 10:53am
There isn't a "difference" in that sense, there aren't any pos and cons, it's more like "What's the difference between C and C++?" There is no both-derectional "difference", C++11 is a superset of C++03 and 98. Look at this: http://en.wikipedia.org/wiki/C%2B%2B11
Jul 29, 2012 at 10:55am
C++ is the language. C++11 is the name for the latest version of C++, so C++11 is still C++. Older versions are C++98 and C++03.
Jul 29, 2012 at 12:33pm
Is there any differences in the code? Or maybe does it add new libraries etc?
Jul 29, 2012 at 1:41pm
Yes, it add new libraries and language features. However, you should not be your concern, as you are a beginner, so likely you don't use them anyway.
Jul 30, 2012 at 7:08am
There are differences in the code ONLY if you want them! Very little stuff is removed, mostly added. Sure, now there are easyer ways to do some stuf, but everything that worked before, works now.
Topic archived. No new replies allowed.