|
From: philip m. <mor...@ho...> - 2003-04-01 14:14:07
|
const int LEN = 80;
char str[LEN];
cout << "Enter string: " << flush;
cin.getline(str, LEN); // use default '\n' delimeter
cout << str << endl;
In the above example getline will just keep reading in characters
(whether they are tabs, spaces or anything else) until:
1) LEN - 1 characters have been read
2) it encounters the delimeter specified by the 3rd argument (which
defaults to the newline character)
3) it reaches the end of the file
whichever happens first - see
http://www.objsw.com/docs/iostream_19.html#SEC19
Philip Mortimer
----- Original Message -----
From: <pr...@le...>
To: <tel...@ya...>
Cc: <dev...@li...>
Sent: Tuesday, April 01, 2003 11:57 AM
Subject: Re: [Dev-C++] Spaces in strings?
>
> Thanks Richard.
> But I don't understand how the input stream being used by getline() (i.e.
> cin) reads in spaces and tabs. Any explanations on that?
>
> <code snippet>
> std::getline(std::cin, name);
> </code snippet>
>
>
> Regards,
> Pranav Negandhi
>
> This email is a natural product. The slight variations in spelling and
> grammar enhance its individual character and beauty and are in no
> way considered to be flaws or defects.
>
>
>
> <snip>
>
> yeah, you've gotten a few emails telling you to uses the getline function
> rather tham cin.
> basically cin will read the input string up to the first white space, this
> is either a space(" ")or a tab(" ") or a enter( "/n" )
> getline however will read everything including spaces and tabs up to the
> first 'enter' or "endl"
> <snip>
>
>
>
>
>
>
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: ValueWeb:
> Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
> No other company gives more support or power for your dedicated server
> http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|