Couldn't compile the simple "Hello World"


 
Thread Tools Search this Thread
Top Forums Programming Couldn't compile the simple "Hello World"
# 1  
Old 03-06-2003
Couldn't compile the simple "Hello World"

So, this is my first C++ program under linux. My OS is Red Hat 8.0, and my codes are like following:

$vi hello.cpp

#include <iostream>
using namespace std;

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

$ g++ -o hello hello.cpp

the error message are:
hello.cpp: In function `int main()':
hello.cpp:4: `cout' undeclared (first use this function)
hello.cpp:4: (Each undeclared identifier is reported only once for each
function it appears in.)
hello.cpp:4: `endl' undeclared (first use this function)

It could run under M$ with VS 6.0. Can someone tell me what I did wrong here? Thanx.
# 2  
Old 03-06-2003
Some ideas:

Instead of:
#include <iostream>

try either:
using namespace std;
or
#include <iostream.h> (deprecated)

Also, instead of cout << ... you can try std::cout << ...
# 3  
Old 03-06-2003
Please don't double post. I deleted the second copy of this thread.

I tried your program with g++ on SunOS and it works for me. I'm not sure what to tell you. You might look at your compiler's docs and ensure that ansi features are enabled.
# 4  
Old 03-06-2003
oombera 's idea was right. I changed <iostream> to <iosteam.h>, and it worked. Maybe it because the the default compile environment is C but not C++? Well, if I want to change to C++ as the default compile language, what should I do?

Perderabo: Sorry, I first posted it to the wrong place, after I copied and pasted, I forgot to delete the old one. Sorry about that.

Well, Thanks for everyone!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Linux

Is it possible to insert compile module after compiled "make" without installing

Hi gud day, I would like to ask if possible to load the driver i compiled module without installing it in the ubuntu-kernel-distro/updates* or simple not executing "make install". what i mean is i compile the compat wireless driver using make and i want to try to load on the system without... (1 Reply)
Discussion started by: jao_madn
1 Replies

3. Programming

Exact meaning of the "world" in "hello world"

Hello! I have a question to native English-speaking people. In the popular program's "hello world" greeting, what meaning the "world" has: "all", "everybody", "people", "friends" or "whole world", "planet", "Earth", "Universe"? In other words, to whom this greeting is addressed: to the... (14 Replies)
Discussion started by: Eugene Muzychen
14 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Programming

dbx: couldn't read "file.cpp"

Anyone know why I might be getting these messages when I'm debugging in dbx? When it stops, I'll get messages like: stopped in get_smtp_line() at line 248 in file "" ($t1) couldn't read "mail_un.cpp" And then I can't list the contents of the file. (2 Replies)
Discussion started by: ctote
2 Replies

6. UNIX for Dummies Questions & Answers

HoHow to compile Linux dialog - "curses.h" missing ?

Hi, I tried native compile Linux dialog for Linux embedded device and got "curses.h" error message. As Linux dialog is already compiled and working as Debian .deb package (installed it). What is a way to import curses.h from other package sources to work for dialog sources compilation in my... (2 Replies)
Discussion started by: darius2
2 Replies

7. Filesystems, Disks and Memory

Why i can't use the tool "turbosoundcfg" to configure the sound in my TurboLinux?

But the page "http://www.chinalinuxpub.com/doc/tlc61/node60.html" says it can.Why ?What can i do? Help me ! Thanks a lot! (3 Replies)
Discussion started by: sensir163
3 Replies

8. UNIX for Dummies Questions & Answers

i don't understand the "sort" command

i have been trying to understand this chapter titled "Searching for Files and Text" for a few weeks now. unfortunately, this chapter is one of those things, that no matter how hard you try and how long you try for, you are incapable of understanding (at least in my case) this entire chapter,... (2 Replies)
Discussion started by: xyyz
2 Replies

9. UNIX for Dummies Questions & Answers

sed 's/~/\^J/g' how to get "^J" on same line as rest of the command.

when ever i type it in it always looks like so echo $file | sed 's/~/\ /g' how can i get it on one line? (6 Replies)
Discussion started by: Optimus_P
6 Replies
Login or Register to Ask a Question