question abt getline

This is a discussion on question abt getline within the C++ Programming forums, part of the General Programming Boards category; what does getline do in this case: suppose i have a file of ppl who have borrowed cd's like this ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    75

    question abt getline

    what does getline do in this case:

    suppose i have a file of ppl who have borrowed cd's like this

    bubba
    2 //number of cd's
    cd1
    cd2
    foo
    0
    anothername
    1
    cd3

    what if i use code like this which goes in a loop

    Code:
    getline(infile, string nName);
    getline(infile, string cdname);
    getline(infile, int number)
    what will happen when it reaches foo, who has no cd's under him or bubba who has just 2 cd taken???

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    that souldn't work at all, seeing as it's not how you setup your data file

    i would do it like this (using the data file you provided):
    Code:
    ...
    while(!infile.eof()) //or something like that
    {
       infile>>name>>number;
       for(number;number>0;number--)
       {
          infile>>cdname[i][];
          i++; //i is preset to 0
       }
    }
    ...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    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. Question About Getline
    By bengreenwood in forum C++ Programming
    Replies: 2
    Last Post: 04-28-2009, 06:13 PM
  2. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 01:14 PM
  3. getline question
    By Swaine777 in forum C++ Programming
    Replies: 2
    Last Post: 03-30-2003, 06:17 AM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. getline question
    By Kings in forum C++ Programming
    Replies: 9
    Last Post: 01-20-2003, 01:01 PM

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