Hello everyone,

I am a college student in his second year of learning C++. Last semester we would use Visual Studio to write and compile our code in. This year we use linux, more specifically the Vi editor. We use linux in two ways, either we use Putty in Windows to SSH into Linux and use vi and the "terminal" or we go to our linux lab and use Ubuntu. When using Ubuntu we use gedit to to write/edit our code and we still use the terminal to compile and link (c++ -c and c++ -o respectivly).

I am getting tired of using Vi so I installed Ubuntu on my laptop and now have a dual boot of both Windows and Ubuntu. I did this so I could quickly write code in gedit and test it using a linux terminal when I am not on campus.

Now to my problem, I created a "Hello World" program on my Ubuntu. I had to get c++ to work by getting g++ (i did the sudo apt-get thing...).

I can get my code to compile and to link but when I try to run the excutable, I get nothing, it just returns to the command line.

At school all I have to do is type in the excutable name and I get the program to run however it is meant to run.

Does anyone know what the issue is?

here is my code just incase thats it (i hope not)

#include<iostream>
using namespace std;

int main()
{
 cout<<"Hello World!"<<endl;

return 0;
}

You need to type ./a.out (or if your program is named with the -o switch) ./nameofyourprogram

See here for an explanation that has a way around it (I'm familiar with the problem but I'm not so much a Linux guy so I don't know the dotfiles as well to advise you one way or another).

Edited 6 Years Ago by jonsca: n/a

Adding . to your PATH is a terrible idea!.


I'm joe hacker, and I've managed to create a short program called 'sl' in your world-writeable temp directory.
You lazily come along as root, and mis-spell 'ls' in an attempt to get a directory listing. You box is now mine.


Stick to ./program for running your local programs.

If you do create a program you want to keep, then create a $HOME/bin directory of your own, and put the file there. Add $HOME/bin to the end of your path, and make sure only you have access to your own bin directory.

And make sure the source for anything useful you create is safely stored somewhere :)

Comments
Thanks.

OP, the Linux man (Salem) has spake. :) I wasn't sure whether it was a good idea so I'm glad you came along. I'd always done the ./ thing but I don't use the *nix on a regular basis enough to know all the tricks and shortcuts and how they break down.

the ./ method worked, does anyone know why i have to do ./ on my home ubuntu and not on my school ubuntu?

Try doing
echo $PATH

at your shell prompt, and see what is in the PATH.
My guess, it contains .

This article has been dead for over six months. Start a new discussion instead.