I’m learning C++ with codeblocks and I’d like to ask if you can post me some good pointers how I can learn the difference between MinGW and Visual studio C++, for example \n and << don’t always behave as I’m expecting. I’m complete newbie, only reached day 2 of an old book “Teach yourself C++ in 21 days” by Jesse Liberty and the program looks like this:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello there."; endln;
cout << "Here is 5: " << 5 << endl;
cout << "The manipulator endln writes a new line to the screen";
cout << "Here is a very big number:\t" << 70000;
cout << "Here is the sum of 8 and 5:\t" << 8+5;
cout << "Here is a fraction:\t\t" << (float) 5/8;
cout << "And here is a very big number:\t" << (double) 7000*7000;
cout << "Remember to replace Niklas with you name";
cout << "Hampus is a C++ programmer!";
return 0;
}
Is MinGW C++ the same as GNU C++? Is there an official standard? any advice for newbie learning / teaching will be appriciated. The book I’m following is “Teach yourself C++ in 21 days” and it is and old edition of the book but I could modify the programs from the first exercise to run and I believe I can use the book since perhaps not many changes were made to the basic C++ since it was published (the edition of the book I own is maybe 10 years old).
Thank you!
Update
After getting the recommendations here, I’ve bought the book C++ Primer.
The only thing that compiler has to enforce (or SHOULD enforce :P) is stuff that’s written in standard. Standard defines behavior, not the implementation, therefore compilers can differ.
First of all, code::blocks is not a compiler, it’s an environment in which people usually use MinGW compiler. Visual Studio on the other hand is an environment that just happens to come with it’s own compiler.
Differences between compilers should be of no concern for you as a beginning c++ programmer and text editor or dev. environment you want to use is up to you, you can program (write the code) in PSpad and then you can compile it with million different compilers.
To sum it up, there’s a standard to which compilers have to (or should) comply. Compilers implement that in whatever way they like and they may add some extra things (like variable size arrays static allocation.) Notice that standard knows nothing about those extensions and therefore doesn’t define their behavior.
Then there’s a text editor of some kind, in which you write your code and compile it with whatever compiler your heart desires.
C++ is not an easy language to learn unless you have prior experience with lower-level (still high level :)) programming language. There’s a lot going on especially if you haven’t encountered pointers and references yet.
I suggest you get a new book possibly even containing information on c++0x / c++11 standard which was officially released couple of months ago.
Also, don’t use
(double)xthis kind of typecasting in c++ since it’s really a c-way of casting types. Usestatic_cast < double > (x)in this scenario. (There are other ways to cast too.)