delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/12/04/05:32:57

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
From: "Goran Bervar" <n DOT e DOT b DOT e DOT r DOT e DOT m AT yahoo DOT com>
Newsgroups: comp.os.msdos.djgpp,comp.lang.c++,alt.comp.lang.learn.c-c++
Subject: Re: More than one letter input
Date: Tue, 4 Dec 2001 11:15:18 +0100
Organization: ARNES
Lines: 70
Message-ID: <9ui7n3$bsg$1@planja.arnes.si>
References: <91509768 DOT 0112031721 DOT 1481a4ee AT posting DOT google DOT com>
NNTP-Posting-Host: lj3-6a.dial-up.arnes.si
X-Trace: planja.arnes.si 1007460900 12176 194.249.2.21 (4 Dec 2001 10:15:00 GMT)
X-Complaints-To: abuse AT arnes DOT si
NNTP-Posting-Date: Tue, 4 Dec 2001 10:15:00 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2919.6600
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Person" <person0000000000 AT yahoo DOT com> wrote in message
news:91509768 DOT 0112031721 DOT 1481a4ee AT posting DOT google DOT com...

Hello, person

do you have any C++  book handy? Your questions are answered in _any_ C++
book. Don't they give you a scripta for your homework? But ok, you tried,
therefore...

> How can I get input for more than one letter (a whole word)??

use std::string type to store strings. 'char' type is meant to hold a single
character only.

> This is what I have so far:
>
>   #include <iostream.h>

As defined by C++ standard, you must include standard headers without .h
extension, eg:

#include <iostream>

as you will nedd std::string, include header for string too:

#include <string>

string , cout and cin are in std namespace. For now, let say it is enough to
tell the compiler you know that:

using namespace std;

>   main()

Standard _requires_ main to return int, therefore:

int main()

>   {
>    char name;

change it to

        string name;

>    int x;

??? Let's have an extra varibale for fun? Delete it.

>    cout << "Name: ";
>    cin >> name;
>    cout << "Hello, " << name << "\n";

use std::endl manipulator instead of '\n' as it flushes the stream. While it
doesn't make any difference in your example you can check a thread in this
NG why:

    cout << "Hello, " << name << endl;

Note: you don't have to return a value in main even if it is declared to
return an int - return 0 is assumed. But most compilers will generate a
warning if you omitt the return statement so no harm is done if you write:

    return 0;
>   }
>

goran


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019