maandag 14 februari 2011

C++ on Ubuntu server

How to compile C++ code on Ubuntu.[1] First, let's start a new text file.

name@computer:~$ nano
#include <iostream>
using namespace std;
int main()
{
cout << "hello world!\n"; return 0; }

I won't go into detail what the commands exactly stand for. You can read them in a tutorial that I linked to before.

Now and save your file as HelloWorld.cpp, and exit. In nano this is ctrl+x. Now we are going to do the compiling.(Finally, the very essence of this post.)

name@computer:~$ g++ HelloWorld.cpp -o HelloWorld

Let's run it to see if it works.

name@computer:~$ ./HelloWorld
hello world!
name@computer:~$

[1] g++ package needs to be installed. See a previous post.

vrijdag 11 februari 2011

Starting to learn C++

I decided to learn some C++, nothing advanced or anything just the basics. First I had to install a Compiler.

I choose Dev-C++.
Download Page
Actual download link

So now I have a compiler, what's next?
What about a good tutorial, preferably in pdf format.
aha, this looks like a good one.
That's that, I can start learning C++. If you happen to know some more advanced tutorials that can be useful when I'm done with this one, please let me know in the comments (you can post anonymously, so make use of that).

edit: If you are going to use the tutorial I linked to in this article you might want to put system("pause"); inside your code when copying the code examples from the tutorial. system("pause"); will make sure you'll be able to see the output of your code. Not using this line will just have the terminal give a quick flash. This is because as soon as the main() function has come to an end, the program will close itself (and a 4 line program comes to an end so fast it's practically invisible).

dinsdag 8 februari 2011

Installing ufw

Okay I have to install ufw. A friend advised me to do so so I could manage some network stuff in the future.

First lets see whether we don't have it already.
~$ dpkg -s ufw
Package: ufw
Status: install ok installed
Priority: optional
Section: admin
Installed-Size: 804
Maintainer: Jamie Strandboge
Architecture: all
Version: 0.30.0-1ubuntu2
Depends: debconf, python (<< 2.7), python (>= 2.6), python-central (>= 0.6.11), debconf (>= 0.5) | debconf-2.0, upstart-job, iptables, ucf
Suggests: rsyslog
Conffiles:
/etc/default/ufw a5a50fd948d40f328e8c1b66d09ca984
/etc/rsyslog.d/20-ufw.conf 322b0e04163744367d1cba9608891bfe
/etc/bash_completion.d/ufw 50de7ccdcddb779093156f133d9c0a5e
/etc/ufw/sysctl.conf 887c00ab9cf13f6944abe88d424c9d08
/etc/init/ufw.conf b85f80257c81675ef38e9db139fb0921
/etc/logrotate.d/ufw 8a9b5120d86b4e59d7e43adaa7b9501c
Description: program for managing a Netfilter firewall
The Uncomplicated FireWall is a front-end for iptables, to make managing a
Netfilter firewall easier. It provides a command line interface with syntax
similar to OpenBSD's Packet Filter. It is particularly well-suited as a
host-based firewall.
Homepage: https://launchpad.net/ufw
Python-Version: 2.6

oh, So apparently I already have it installed.
:-)
Here is a link with some more information about ufw:
UFW Ubuntu help

donderdag 3 februari 2011

Installing g++

G++ is a compiler for C++. I wanted to install this because I wanted to learn the basics of C++ and so I need a compiler to compile my "Hello World" program.

Installing G++ can be a pain in the ass though. I've found this out on several forum after failing to do it on my own. Several people advised to install the package 'build-essentials' because it included G++ and didn't give problems installing. I didn't want to install 'build-essentials' though so I kept on looking for a solution.

Eventually I found out that
$sudo aptitude update && sudo aptitude install g++
worked for me. So apparently I just had to update to make it work.

And another useful command is:
$dpkg -s
this will tell you whether your package is installed.