LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-13-2003, 06:57 PM   #1
davmer
LQ Newbie
 
Registered: Mar 2003
Location: Tasmania, Australia..the best place in the world..clean air & clean water..purely subjective of course!!!
Distribution: Red Hat 8.0
Posts: 20

Rep: Reputation: 0
Question C++ Red Hat8.0 - trouble with cout


Hi,

Have just installed Red Hat 8.0 and am testing c++ environment

Wrote a simple program:

#include <iostream>
using namespace std;
void main(){
cout << "Hello World";
}

compiled OK with g++ -o hello hello.cpp

ran OK with ./hello

no output was seen just a return to the prompt

wrote an equivalent program with gcc (C compiler) with success

also wrote the same c++ code on an AIX machine at work which worked fine

anybody throw any light?
 
Old 03-13-2003, 07:01 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
you didn't end the line. try:

Code:
cout << "Hello World" << endl;
 
Old 03-13-2003, 07:11 PM   #3
davmer
LQ Newbie
 
Registered: Mar 2003
Location: Tasmania, Australia..the best place in the world..clean air & clean water..purely subjective of course!!!
Distribution: Red Hat 8.0
Posts: 20

Original Poster
Rep: Reputation: 0
Thanks Chris for your prompt reply...this is wonderful if i can get this kind of response to problems!!!

I will try your suggestion, although the endl doesnt seems to be required on other implementations of C++

davmer
 
Old 03-13-2003, 07:42 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
The problem you might be facing is that
it is output *before* your prompt without a
newline? Guess that's why Chris suggested
the endl in the first place :} ... he's quite clever
for a pom :}
/me runs for cover...

Cheers,
Tink
 
Old 03-13-2003, 07:48 PM   #5
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
Quote:
Originally posted by davmer
...although the endl doesnt seems to be required on other implementations of C++
That's because G++ 3.2 is better than the others.
 
Old 03-13-2003, 08:14 PM   #6
davmer
LQ Newbie
 
Registered: Mar 2003
Location: Tasmania, Australia..the best place in the world..clean air & clean water..purely subjective of course!!!
Distribution: Red Hat 8.0
Posts: 20

Original Poster
Rep: Reputation: 0
thanks Tink,

of course your reply is useful and appreciated

I wont be able to try this until i get home tonight

but i have tried compiling this without endl on both AIX, AS400 and Visual C++; all return Hello world so i am getting pretty suspicious that there is something else going on

but anyway i will try tonight & let you know how i went

once again...thanks to everybody for trying to help me...i feel really excited to be part of this community
 
Old 03-13-2003, 08:17 PM   #7
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
Think about it logically. If there is no newline, than why shouldn't the command prompt over write the result?
 
Old 03-13-2003, 08:21 PM   #8
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
Code:
#include<stdio.h>

int main() {

  printf("Hello World ------ Hello World --------!");
  return 0;
}
Result of running the program:
[prompt]$ --------!

Code:
#include<stdio.h>

int main() {

  printf("Hello World");
  return 0;
}
Result of runing this different version:
[prompt]$
 
Old 03-13-2003, 08:22 PM   #9
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
Note, I condensed my prompt. Don't want to give away any details about my system!
 
Old 03-13-2003, 08:23 PM   #10
davmer
LQ Newbie
 
Registered: Mar 2003
Location: Tasmania, Australia..the best place in the world..clean air & clean water..purely subjective of course!!!
Distribution: Red Hat 8.0
Posts: 20

Original Poster
Rep: Reputation: 0
yes gtkuser..but correct me if i am wrong, would not the prompt be presented on the same line but at the next char after my string.. thus i would see

Hello World$

this is how it appears in AIX actually without endl and also when i compiled with gcc using printf without \n under my red hat install
 
Old 03-13-2003, 08:35 PM   #11
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
It's possible that the prompt would appear after the output, however it's not the case with gnome terminal on RH8.0 using either a C program (gcc) or a C++ program (g++).

Since the program has terminated, and control is returned back to the operating system, it's difficult to say if the prompt is going to overwrite or else appear at the end of the output. With Gnome Terminal, the prompt overwrites.

People have asked this question before here, but the output is there, it's just overwritten. Now lets get on with writing some applications!
 
Old 03-13-2003, 10:20 PM   #12
davmer
LQ Newbie
 
Registered: Mar 2003
Location: Tasmania, Australia..the best place in the world..clean air & clean water..purely subjective of course!!!
Distribution: Red Hat 8.0
Posts: 20

Original Poster
Rep: Reputation: 0
thank you gtkuser,

i apologise if this is going over old ground for you and i thank you for your suggestions which i will try this evening
the whole idea of course is to write applications but i was not aware of the peculiarity with GNOME as i have just started playing with it and so when it did not perform as per my experience i thought it was worth persuing before trying more difficult things. the whole idea behind me installing linux is to gain skills in linux, c++ and x windows so i ask your tolerance at this time

as time is going by i have become disallusioned with microsoft & what it represents and i look forward to the day when linux is an equal alternative...i want to be ready for the revolution

in comparative terms i know nothing...as you say enough talk...let the challenge & enlightenment begin......

look forward to talking to you again on more "meaty" topics
 
Old 03-13-2003, 10:30 PM   #13
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
First time I used gcc or g++. I think I did my first program in gcc, and it was a hello world program. I forgot the newline character. So I did the same thing. Nothing displayed on the screen.

Linux is a better platform for research because it has an open implementation. Since C/C++ are research languages, and the platform is implemented in C, than it would be hard to beat Linux, unless you worked for some vendor and had access to implementatiion code. Yet even in that case, you would not be able to change that code or add anything to it, unless you had approval.

I am learning Standard C++ at this time, so it sounds like we have similar interests. I have not begun to study the kernel yet, but I intend to some time next year.

What books are you using to learn C++?

Last edited by GtkUser; 03-13-2003 at 10:32 PM.
 
Old 03-13-2003, 10:55 PM   #14
davmer
LQ Newbie
 
Registered: Mar 2003
Location: Tasmania, Australia..the best place in the world..clean air & clean water..purely subjective of course!!!
Distribution: Red Hat 8.0
Posts: 20

Original Poster
Rep: Reputation: 0
I am using what i consider an excellent book

C++ A beginner's - Guide Herbert Schildt (McgrawHill/Osbourne)

it starts from the basics and goes through to advanced topics like templates. the thing i liked about this book is that it teaches c++ from the beginning, even the hello world example uses c++ contructs, whereas a lot of books start of with c and then progress to c++. Also the print is larger which makes it easier to read for us old guys!!!!

Now that i have linux installed I am actually now going to use this book to try out all of the examples in the book. i think a good way to reinforce a language is to get down & type the code, compile & run..even if the examples are trivial in nature the constant reinforcement sets the paradigm in your head so that when a real project is attempted the basics come second nature

the first book i bought was

Practical C++ by Rob Mcgregor (QUE)

which i found hard going (small print, some 850 pages). Having said that i think having nearly completed the basic book i will now get a lot of value from mcgregor's book as it goes into more advanced topics like containers that the basic one doesnt ..it is very comprehensive and i think an excellent reference now that i am starting understand some of the concepts
 
Old 03-13-2003, 11:04 PM   #15
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
At the Association Of C and C++ Users < http://www.accu.org > there is a book review section. Some of the book reviewers are members of the ISO/IEC C++ Standards comittee.

At any rate, I agree, that it's good practice to start off with building some trivial classes, than adding functionality to them.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ cout not working :( Longinus Programming 10 08-01-2004 08:32 PM
red hat8/xp home network issues ceph Linux - Networking 1 11-17-2003 09:11 PM
PCtel driver Red Hat8 fat_anis Linux - Hardware 3 07-11-2003 03:40 AM
Red Hat8 GUI Login screen + Caddy Ravenator Linux - Hardware 1 04-14-2003 07:46 PM
Add param t boot up in Red Hat8? ShadowGod Linux - General 1 01-09-2003 09:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration