1.

Solve : C++ question?

Answer»

k , was reading a beginners guide to c++

#include <iostream.h> // file that includes
// INFO on input and ouput

main() //aways 1st function in c++ console apps[mandatory]
{
cout<<"Hey Bevis this is cooool";

return 0;

}


i took this code and saved it as cpp.cpl , then i opend it and it opened itself a couple hundred times what did i do wrong?CPL extensions are associated with the Windows Control Panel. Could you not use an actual program name with a CPP extension?

Couple things:

1. You need to name it as NAME.cpp, not cpp.cpl. It's the cpp file that is compiled into an EXE.

2. Your code will not compile. You need to change this line:

main ()

to this:

int main ()

3. ALSO, after the #include line, before the int main(), you need to do this:

USING namespace std;

So, it should look like this:

Code: [Select]#include <iostream> // file that includes
// info on input and ouput

using namespace std; //Allows use of cout, cin and other commands

int main() //aways 1st function in c++ console apps[mandatory]
{
cout << "Hey Bevis this is cooool";

return 0;

}
Save that as SOMETHING.cpp, replacing "something" with whatever name you want.

Cheers,
Dilbert

EDIT: Note that I used #include , not #include . iostream.h is an old file, used primarily these DAYS for C, not C++. With a simple program like this, you won't notice a difference, but when you get into Objects, the difference will be much more apparent.



Discussion

No Comment Found