C++ in knoppix

Status
Not open for further replies.

Manojap

Broken In
Give an example of cpp progrm in knoppix, a linux flavor.
Pleas explain..
Compiling
viewing out put
 

QwertyManiac

Commander in Chief
Let's take a sample code:
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]

Now to compile this:
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]

To finally run out compiled binary:
Code:
./outfile [color=#408080][i]# or use: sh outfile[/i][/color]

Do all this in the terminal. If any other problem persists, do report here.
 

ambika

learnhardy
Let's take a sample code:
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]
Now to compile this:
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]
To finally run out compiled binary:
Code:
./outfile [COLOR=#408080][I]# or use: sh outfile[/I][/COLOR]
Do all this in the terminal. If any other problem persists, do report here.

Nice explaination QWERTY ......can u please ......assign me same for the c language.
only conio.h not works in gcc .....?any other differences ....??
 
Status
Not open for further replies.
Top Bottom