LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 01-09-2002, 12:20 AM   #1
jstu
Member
 
Registered: Jan 2002
Distribution: slackware
Posts: 193

Rep: Reputation: 30
Question c++


just starting to learn c++ and I cant get my program to display any input heres a simpel one that would not work.

#include <iostream.h>

void main()
{
cout << "what is your name\n";

char name[20];

cin >> name;

cout << "hello" << name << "!";

}

It will ask for a name I'll type it in and when I hit enter the program terminates.
thanks in advance.
 
Old 01-09-2002, 07:48 AM   #2
mtsinc
LQ Newbie
 
Registered: Jan 2002
Location: Jacksonville, FL
Distribution: RedHat
Posts: 26

Rep: Reputation: 16
I tried it under g++ V2.96 and it ran fine. The only thing I'd do is change the output line slightly:

cout << "Hello " << name << "!\n";

One problem you could have is that without the trailing "\n", the output buffer might not flush. In fact, a better way to prompt would be:

cout << "What is your name? ";
cout.flush();

Otherwise the prompt might not be forced out in time to be seen.
 
Old 01-09-2002, 01:53 PM   #3
jstu
Member
 
Registered: Jan 2002
Distribution: slackware
Posts: 193

Original Poster
Rep: Reputation: 30
cool

ya it works
thanks
 
  


Reply



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



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

All times are GMT -5. The time now is 10:14 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