← ppnm

Exercise "Hello, World!"

Tasks

  1. Install the C++ compiler on your system. There are two major open implementations of C++: g++ and Clang.

    • Debian based systems:

    sudo apt install g++
    sudo apt install clang
    • Termux:
    apt install Clang
    • MacOS: it seems that Clang is included in Xcode.
  2. Create a directory for the exercise inside your repository, let's say "~/repos/ppnm/exercises/hello",

    mkdir -p ~/repos/ppnm/exercises/hello
  3. Go to your directory (remember to use the completion feature of your shell !):

    cd ~/repos/ppnm/exercises/hello
  4. Create a Makefile with the following content (mind the tabulators!) (and you can omit the comments).
    Out.txt : hello             # Out.txt depends on hello.exe
    	./hello > Out.txt        # run hello.exe, send output to Out.txt
    hello: hello.cc                 # hello depends on hello.cc
    	clang++ -o hello hello.cc  # compile-and-link hello.cc, save executable in hello
    clean:
    	rm -f Out.txt hello
    
  5. Create a file hello.cs (hello.cc) with the following content,
    • hello.cs:
    class hello{
    static int Main(){
    	System.Console.WriteLine("Hello, World!");
    	return 0;
    	}
    }
    
    • hello.cc:
    #include<iostream>
    int main(){
    	std::cout << "Hello, World!" << std::endl;
    	return 0;
    }
    
  6. Run "make" and debug ;)

Hints