[color=#BC7A00]#include <iostream> [/color][color=#408080][i]// No .h's for standard libraries anymore
[/i][/color]
[color=#008000][b]using[/b][/color] [color=#008000][b]namespace[/b][/color] std;
[color=#408080][i]// All the standard headers use this namespace,
// so lets make it common.
// Else we type std::cout and std::endl, and so on.
// Just think of it as,
// cout, endl, cin, etc default functions
// belong to this large class
// (actually name-space) called [B]std[/B] (standard).
[/i][/color]
[color=#B00040]int[/color] main () [color=#408080][i]// main must always return int now on ...
[/i][/color]{
cout[color=#666666]<<[/color][color=#BA2121]"Hello"[/color][color=#666666]<<[/color][color=#BA2121]" "[/color][color=#666666]<<[/color][color=#BA2121]"World"[/color][color=#666666]<<[/color]endl;
[color=#008000][b]return[/b][/color] [color=#666666]0[/color];
}
[color=#408080][i]// Save as file.cpp[/i][/color]
[color=#408080][i]# Use g++, the default GNU C++ compiler.
[/i][/color]g++ file.cpp -o outfile
[color=#408080][i]# Outfile is the output (binary, executable) file name. By default it is a.out (Assembler.output)
[/i][/color]
./outfile [color=#408080][i]# or use: sh outfile[/i][/color]
Let's take a sample code:
Now to compile this:Code:[COLOR=#bc7a00]#include <iostream> [/COLOR][COLOR=#408080][I]// No .h's for standard libraries anymore [/I][/COLOR] [COLOR=#008000][B]using[/B][/COLOR] [COLOR=#008000][B]namespace[/B][/COLOR] std; [COLOR=#408080][I]// All the standard headers use this namespace, // so lets make it common. // Else we type std::cout and std::endl, and so on. // Just think of it as, // cout, endl, cin, etc default functions // belong to this large class // (actually name-space) called [B]std[/B] (standard). [/I][/COLOR] [COLOR=#b00040]int[/COLOR] main () [COLOR=#408080][I]// main must always return int now on ... [/I][/COLOR]{ cout[COLOR=#666666]<<[/COLOR][COLOR=#ba2121]"Hello"[/COLOR][COLOR=#666666]<<[/COLOR][COLOR=#ba2121]" "[/COLOR][COLOR=#666666]<<[/COLOR][COLOR=#ba2121]"World"[/COLOR][COLOR=#666666]<<[/COLOR]endl; [COLOR=#008000][B]return[/B][/COLOR] [COLOR=#666666]0[/COLOR]; } [COLOR=#408080][I]// Save as file.cpp[/I][/COLOR]
To finally run out compiled binary:Code:[COLOR=#408080][I]# Use g++, the default GNU C++ compiler. [/I][/COLOR]g++ file.cpp -o outfile [COLOR=#408080][I]# Outfile is the output (binary, executable) file name. By default it is a.out (Assembler.output) [/I][/COLOR]
Do all this in the terminal. If any other problem persists, do report here.Code:./outfile [COLOR=#408080][I]# or use: sh outfile[/I][/COLOR]
Thats because ANSI C - 99 standards. Not because of gcc.I guess that's about it. The main() must return int, and can't be void.