Thread: white spaces

  1. #1
    Registered User
    Join Date
    Jan 2004

    white spaces

    Just something I dont understand...Lets say you had the follwing data in a file:

    cat and mouse
    dog and flea

    fish and bait
    bird and worm


    if I read in the file as

    while (in.getline (str1, MAX,'\n'))
        in >> ws;
        in.getline( str2, MAX,'\n');
        in >> ws >> id >> ws >> ws;
    it doesnt work. But if I write the last line as
    in >> ws >> id >> ws;
    everything is fine. Why is that? There are 2 enter's before the next block of data.

  2. #2
    Registered User
    Join Date
    Nov 2001
    One solution is std::getline().

    std::string sInput;

    while (std::getline(cin, sInput))


  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    I believe ws takes in all the whitespaces before the next character/until EOF, so therefore, after the first ws executes, there's nothing left for teh second ws to get rid of...
    Join is in our Unofficial Cprog IRC channel
    Channel: #Tech

    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading white spaces? oh and scanf_s
    By RobotGymnast in forum C++ Programming
    Replies: 7
    Last Post: 11-01-2008, 05:32 AM
  2. white spaces ...
    By eagles in forum C++ Programming
    Replies: 6
    Last Post: 01-13-2006, 07:55 AM
  3. Replies: 1
    Last Post: 03-08-2005, 12:02 PM
  4. string input...with white spaces?
    By Pureghetto in forum C Programming
    Replies: 6
    Last Post: 03-10-2003, 01:52 PM
  5. Reading in text file into an array, white spaces...
    By error in forum C++ Programming
    Replies: 12
    Last Post: 01-14-2003, 09:39 AM