TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: FRANK MASINGILL
from: CLIFF RHODES
date: 1997-05-18 11:07:00
subject: Strings in C++

--> Frank Masingill wrote to Cliff Rhodes <--
FM>    Is there a way to enter and retrieve a string like a
FM>first and last name all in one string using the iostream
FM>library?  I seem not to have any examples that provide for
FM>that.  One seems to have to set up for FIRSTNAME and
FM>LASTNAME as separate strings.
Hi, Frank. Yes there are several ways to do it. Here's one that use 
the getline() member function of the istream class:
#include 
int main(void)
{
   const int Namelen = 36;   // chars in longest name supported
   char name[Namelen];       // buffer for name
   cout << "Enter name: ";   // prompt user for name
   cin.getline(name, Namelen);  // Gets up to Namelen chars into name,
                                // or ends when a newline occurs.
                                // cin is an istream, so we call one
                                // of its member functions this way.
   cout << "\nThe name is: " << name << endl;
   return 0;
}
Cliff Rhodes
cliff.rhodes@juge.com
X CMPQwk 1.42 1692 X"The struggle alone pleases us, not the victory." - 
Blaise Pascal
--- Maximus/2 3.01
---------------
* Origin: COMM Port OS/2 juge.com 204.89.247.1 (281) 980-9671 (1:106/2000)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.