# C++ in knoppix



## Manojap (Jan 1, 2009)

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


----------



## QwertyManiac (Jan 1, 2009)

Let's take a sample 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:

```
[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:

```
./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 (Jan 3, 2009)

QwertyManiac said:


> Let's take a sample code:
> 
> ```
> [COLOR=#bc7a00]#include <iostream> [/COLOR][COLOR=#408080][I]// No .h's for standard libraries anymore
> ...



Nice explaination QWERTY ......can u please ......assign me same for the c language.
only conio.h not works in gcc .....?any other differences ....??


----------



## QwertyManiac (Jan 3, 2009)

I guess that's about it. The main() must return int, and can't be void.


----------



## Garbage (Jan 3, 2009)

QwertyManiac said:


> I guess that's about it. The main() must return int, and can't be void.


Thats because ANSI C - 99 standards. Not because of gcc.


----------

