Thread: question about eof

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    To read in text with spaces, use getline instead of >>. It has nothing to do with char str[50] versus string.

    Both getline and >> work with strings and character arrays (there is a different version for each). If you are having a problem, post the code and example input.

  2. #17
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    i just noticed i made a dumb error i was over doing the char array limit lol i got that one to work now...but the string getline yea i dont know how to do that version isnt it getline(cin,str,'\n'); or something thats what i saw on the main page of this site and i couldnt get it to work?
    hooch

  3. #18
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Code:
    #include <iostream>
    #include <string>
    // ...
    std::string str;
    while (std::getline(std::cin, str))
    {
      // ... use str.
    }
    That's it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. EOF messing up my input stream?
    By Decrypt in forum C++ Programming
    Replies: 4
    Last Post: 09-30-2005, 03:00 PM
  2. Strange EOF happenings
    By fatinez in forum C Programming
    Replies: 6
    Last Post: 09-23-2003, 08:37 PM
  3. files won't stop being read!!!
    By jverkoey in forum C++ Programming
    Replies: 15
    Last Post: 04-10-2003, 05:28 AM
  4. EOF question, scanf also
    By newbie123 in forum C Programming
    Replies: 4
    Last Post: 01-31-2003, 04:15 PM
  5. what does this warningmean???
    By kreyes in forum C Programming
    Replies: 5
    Last Post: 03-04-2002, 07:53 AM