C++'s Hello World is similar to Go's (golang), but there are some differences. The similarity is that both C++ and Go create a file that is executed natively on the platform it is compiled to. Also both C++ and Go follow a procedure of compile then link. The main differences, for the Hello World program, are in the expressiveness and the syntax. Writing hello world in C++ requires the following steps:
Step 1: Create a C++ source file
The source file for Hello World thus looks like the following:
__________________________________________________________________________________
#include <iostream>
using namespace std;
int main(int argc, const char** argv){
cout<<"Hello World in C++ from ecocrypt.blogspot.com"<<endl;
return 0;
}
__________________________________________________________________________________
Save this to any file name you like, but typically, you will have to have a .cpp extension on the end of the file name. A good name to choose for this example would be helloworld.cpp.
Step 2: Compile the C++ Source
At a command prompt, type the c++ compiler-linker command:
prompt % c++ HelloWorld.cpp
This will typically do a 2 step process of compiling and linking. Therefore no intermediate object files will be created. The result of this will be to produce an output file called a.out, or a.exe.
Step 3: Running HelloWorld
At the command prompt, type:
prompt % a.out (or a.exe on windows)
Hello World in C++ from ecocrypt.blogspot.com
Congratulate yourself! You have successfully installed a C++ compiler, and created a simple hello world executable.
No comments:
Post a Comment
All comments are greatly appreciated! Comments will be moderated, and usually appear within 1 day. If you like a post, instead of saying you like it, vote for it or digg it (links provided). If there is any ERROR, PLEASE Comment I strive for good quality complete content.