What happened to my C++?

About 2 years ago I finsihed taking my 3rd year of C/C++ courses. Now, I’m trying to get back into practice with my programing over the summer so I sit down on my SuSe OS pull up vi and write “Hello World” just as I remember it from High School. I get back a seriers of errors that don’t make much sence, but between my father and I, and knowing who to ask and where to look we find that my origional program which looked like this:

#include <iostream.h>

main()
{
cout << "Hello World
";
}

should look like this:

#include <iostream>

int
main()
{
std::cout << "Hello World
"
return 0;
}

my main question is about the new format for my old buddie ‘cout’ what can anyone tell me about it. Do you need to do the ‘std::cout’ for all instances of the function? Just the first time? what about when linking? (ie: cout << "the answer is " << answ; ) And when/why was it changed? and is there anything else I should know?

You need the std::cout because you didn’t define it in the header of the file. If you include <iostream> or most other predefined C++ headers, you have to add using namespace::std; to get access to it’s members. In that case, you’d have access to everything in the std, but for such a simple program, you can add each member as you need them by adding using std::cout;. You also don’t need to add .h to header files that are included with the language anymore.

It’d look like this:

#include <iostream>
using namespace::std; // Includes the entire std -OR-
using std::cout; // less amout of overhead.

/* Use one way or the other, remember if you use the second way, each time you want to use another member of the std, you’d have to do the same thing */

int main()
{
cout << "Hello World
";
return 0;
}

Or you can just keep doing it the way you are, it doesn’t really matter, but I think this is a bit cleaner then having to scope everything in everywhere.

C++ is overcomplicated. So is Java. And C#. Best to just get far, far away from computers.

Ok, Thanks for clearing that up for me. What else is in this std… what is it a library? And are there other examples of something similar that I should know about?

std is the standard namespace. Everything in the standard libraries is in it.

Uh…you took 3 years of C/C++ and you don’t even know what the standard library is?

Not to be an ass or anything, but I find that amazing.

Yeah. Let’s go back to the days of Visual Basic when you could draw the gui out with a mouse.

When I took C/C++ the first program that I wrote worked. Something has changed and I have not stayed up on it, quite frankly I was not expecting it. I know what a standard library is, but to me that’s a ‘.h’ file. this “standard namespace” is new and unheard of. If you want I think I can did up some of my old code and show you how we did it in the old days.

The easiest way to fix old code that doesn’t use the std namespace is to just add a “using namespace std;” declaration in it somewhere. There’s some confusing things. I think some compilers include the old header files with a .h at the end and those header files might not use namespaces.