Thread: cin for strings?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Quote Originally Posted by Brain Cell
    cin reads a string up to (but not including) the first whitespace it encounters. Use cin.getline instead :
    Code:
    cin.getline(mystring, sizeof(mystring), '\n');
    first argument is your string , second speicifies the max input number , third is the delimeter (its '\n' by default so you don't have to include it).

    hope this helps
    Bang on, baby!
    Actually, not quite, although Brain Cell may have gotten that from something I posted(which was incorrect--sorry!). It's actually the >>operator that is programmed to skip leading whitespace it sees, then start reading in data, and finally stop reading data when it encounters a whitespace character(space, tab, or newline)--not cin. If you learn about file I/O, you will see that the >>operator does the same thing with other streams besides cin.

    (I'll have to try and search for that post of mine, and correct it. )
    Last edited by 7stud; 04-03-2005 at 01:38 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cin problem
    By mikahell in forum C++ Programming
    Replies: 12
    Last Post: 08-22-2006, 11:14 AM
  2. getline(function)??
    By dac in forum C++ Programming
    Replies: 7
    Last Post: 03-10-2006, 12:42 PM
  3. cin not allowing input after first use of function
    By Peter5897 in forum C++ Programming
    Replies: 5
    Last Post: 01-31-2006, 06:29 PM
  4. Overriding Cin with Cout
    By Tainted in forum C++ Programming
    Replies: 5
    Last Post: 10-06-2005, 02:57 PM
  5. Problem Calling Destructor, and prob with cin.
    By imortal in forum C++ Programming
    Replies: 2
    Last Post: 10-10-2003, 09:29 AM