Can't Get "Hello world" to run

Pages: 12
Dec 17, 2008 at 10:38pm
I am new to programming and am trying to follow an online tutorial to learn the basics of C++. I did the very simple steps outlined:

http://www.intap.net/~drw/cpp/cpp02_01.htm
http://www.intap.net/~drw/cpp/cpp02_02.htm

I must be typing in the wrong path or something, because every time I do it I get a > as a result and nothing I do from that point on makes any difference.

If it matters, I'm using GNOME Terminal 2.23.1.1

Suggestions? Sorry, I am a complete novice.
Last edited on Dec 17, 2008 at 10:38pm
Dec 17, 2008 at 10:46pm
Try putting std:: in front of cout...or put using namespace std; before your main().

Also, are you running the .exe it create after you compiled it?
Dec 17, 2008 at 10:54pm
It apparently isn't compiling properly. No .exe file.
Dec 17, 2008 at 11:12pm
here you go. You will notice I added a line "using namespace std;" This tell the compiler what "cout" "cin" "endl" and others do.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//include this file for cout
#include <iostream.h>

using name space std;

int main() {

  //print out the text string, "Hello, World!"
  cout << "Hello, World!" << endl;

  return 0;

}



Also you might want to replace return 0; with cin.get();. That will tell the program to wait for you to press the return key b4 going on.


I know its bad form to just give the answer. Sometimes its just best to see a problem corrected. It it can be a fast and easy way to learn learn how something should be done.

igneousquill, I have some c++ books I can send you a link to. Send me a PM if you want them
Last edited on Dec 17, 2008 at 11:15pm
Dec 17, 2008 at 11:26pm
gcc doesn't add .exe extensions to executables.

To run an executable name "hello" in the current directory, use ./hello
Dec 17, 2008 at 11:29pm
I really appreciate the attempts to help. I really think the problem is when I'm trying to compile. The file exists as hello.C (I'm in Linux). I'm taking the path from the location I can see when I look for the file. I start off in the terminal at the prompt with g++ but after I put everything in it just goes to a > prompt and does nothing more. I'm clueless.

I've been playing around with Python for a couple of weeks now and wanted to start getting familiar with C++, but never encountered anything like this. Stumped.
Dec 18, 2008 at 12:07am
the problem is the program has an error
there shud not be any blank space between name and space

it shud be

using namespace std;

it shud work now

try out
Dec 18, 2008 at 12:09am
I've never heard anything like that. Did you try using a different terminal, like xterm, or Konsole?
Dec 18, 2008 at 12:17am
i ve included balnk between name and space in 'namespace' many times
myself and found it hard to understand the error

my previous post shud solve the problem

Dec 18, 2008 at 12:30am
I tried namespace all as one word but the same result.

I really suspect it's something with the way I'm typing this into the terminal.

The "path" should refer to the location of the file in the directory, right? Copying exactly and it still doesn't work.
Dec 18, 2008 at 12:39am
whick flavour of ubuntu u r using
can you tell me? so that i can help you

or do this

$locate iostream
give the output of this shell command in your system




Dec 18, 2008 at 12:40am
I'm using 8.10.
Dec 18, 2008 at 12:42am
in the synaptic package manager

check whether build-essential package is installed in your system

if not install it and that shud solve ur problem
Dec 18, 2008 at 12:47am
Already installed build-essential package.
Dec 18, 2008 at 12:48am
whats the output of
$locate iostream
Dec 18, 2008 at 12:49am
bash: iostream: command not found
Dec 18, 2008 at 12:52am
try to remove build-essential package

and try to install it again

also make sure g++ is installed properly

Dec 18, 2008 at 12:54am
the command shud be locate

$locate iostream

it searches for the occurrence of iostream in your filesystem
did you try this command properly


$'locate iostream'

(quotes for clarity)
Dec 18, 2008 at 1:00am
yes, I did the command that way and the result was
bash: iostream: command not found
Dec 18, 2008 at 2:18pm
Okay, I'm going to feel bad if this is the problem, but how should the file name end? I'm working in Ubuntu Linux and assumed .C would be the correct ending, but on another forum I read about someone using .cpp, which I thought was only for Windows. I'm at work using a Mac right now so I can't test it.
Pages: 12