I've started learning this recently and received a book "C++ from the ground up" (I was also playing around with c code for a little while previous). Using Visual Studio Pro 2010 which may seem a little overkill when I'm going to be compiling single sources of code but I like the IDE and it's suiting me fine.
My query is this. I've had to make a few changes to the examples given in the book to make it compile and I'm just trying to find out why this is, the book was published in 1994 so I'm wondering has C++ changed somewhat since then, is it the compiler I am using, or is it to do with Windows itself?
Anyhoo, one of the code examples in the book is:
And to make it compile and work I've had to amend it to this:
The std namespace is quite important but if it wasn't needed back in 1994, why should I need to add it now? Surely all previous code should still compile regardless, yes? However, all this helps my understanding and learning and I like to know why things aren't working.
My query is this. I've had to make a few changes to the examples given in the book to make it compile and I'm just trying to find out why this is, the book was published in 1994 so I'm wondering has C++ changed somewhat since then, is it the compiler I am using, or is it to do with Windows itself?
Anyhoo, one of the code examples in the book is:
Code:
#include <iostream.h> main() { int gallons, litres; cout << "Enter the number of gallons: "; cin >> gallons; // takes an input from the user litres = gallons * 4; // convert to litres cout << "Litres: " << litres; return 0; }
Code:
#include <iostream> // as opposed to iostream.h using namespace std; // this has been added int main() // else reports back with error { int gallons, litres; cout << "Enter the number of gallons: "; cin >> gallons; // takes an input from the user litres = gallons * 4; // convert to litres cout << "Litres: " << litres; return 0; }
Comment