question about eof

This is a discussion on question about eof within the C++ Programming forums, part of the General Programming Boards category; To read in text with spaces, use getline instead of >>. It has nothing to do with char str[50] versus ...

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    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,328
    Code:
    #include <iostream>
    #include <string>
    // ...
    std::string str;
    while (std::getline(std::cin, str))
    {
      // ... use str.
    }
    That's it.

Page 2 of 2 FirstFirst 12
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, 03:15 PM
  5. what does this warningmean???
    By kreyes in forum C Programming
    Replies: 5
    Last Post: 03-04-2002, 06:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21