Can't Get "Hello world" to run

Pages: 12
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
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?
It apparently isn't compiling properly. No .exe file.
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
gcc doesn't add .exe extensions to executables.

To run an executable name "hello" in the current directory, use ./hello
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.
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
I've never heard anything like that. Did you try using a different terminal, like xterm, or Konsole?
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

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.
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




I'm using 8.10.
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
Already installed build-essential package.
whats the output of
$locate iostream
bash: iostream: command not found
try to remove build-essential package

and try to install it again

also make sure g++ is installed properly

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)
yes, I did the command that way and the result was
bash: iostream: command not found
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