-
Compile help?VC++
okay, im just starting c++(today), can you explain to me how to compile/what im doing wrong here?
Code:
#include <iostream.h>
int main()
{
cout << "Hello World!\n";
return 0;
}
and it compiled without errors(i pressed the f7 button) and i found a exe file named cpp1.exe,
when i run it, it looks like a bat file, then closes..without saying anything..
what am i doing wrong? am i even in the right forum?
-
Re: Compile help?VC++
Code:
#include <iostream> //<iostream.h> is deprecated
int main()
{
cout << "Hello World!\n";
system( "pause" );
return 0;
}
Try this. :)
-
Re: Compile help?VC++
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(5) : error C2065: 'cout' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(5) : error C2297: '<<' : illegal, right operand has type 'char [14]'
Error executing cl.exe.
Cpp1.exe - 2 error(s), 0 warning(s)
-
Re: Compile help?VC++
Code:
#include <iostream> //<iostream.h> is deprecated
#include <iostream.h>
int main()
{
cout << "Hello World!\n";
system( "pause" );
return 0;
}
works perfect, thanks!
can you explain it at all?
-
Re: Compile help?VC++
Code:
#include <iostream> //<iostream.h> is deprecated
using namespace std;
int main()
{
cout << "Hello World!\n";
system( "pause" );
return 0;
}
Sorry this should work. :)
-
Re: Compile help?VC++
cool, can you please explain the code, or could someone?
-
Re: Compile help?VC++
Code:
#include <iostream> //a header file that's part of the C(++) standard, containing declarations for various functions/types etc. you're gonna use (cout etc.)
using namespace std; //The namespace under which you're working, included here because all declarations in the standard headers are in this namespace
int main() //The program starts at this function, the function returns an int type
{
cout << "Hello World!\n"; //Sends the string "hello world!" with a newline char on the end (making a new line) to the console output stream
system( "pause" ); //Runs the system command pause (causing the press any key to continue text)
return 0; //returns a 0, indicating the successfull termination of this program
}
-
Re: Compile help?VC++
Use Firefox or Opera to go here for a very long and thorough breakdown of the Hello application.
And get rid of the system("pause"). Either invoke the application by pressing Ctrl+F5 in the IDE, or use a console (Run->"cmd") to navigate to the output directory and call the application on the console. In both cases, the console will stay open and you see the output, without adding a non-portable and nonsensical piece of code.