getline comparison + audiobooks

This is a discussion on getline comparison + audiobooks within the C++ Programming forums, part of the General Programming Boards category; I am trying to read a formatted file where the first two characters in each line denotes the type of ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    20

    getline comparison + audiobooks

    I am trying to read a formatted file where the first two characters in each line denotes the type of line it is, it's related to music.
    For instance "T:" denotes its the title.
    One song can have many titles (there folk songs) which will be on consecutive lines in the same file

    T:Mullingar Lee, The
    T:Nine Pint Coggie, The
    I want to make it so if one song has many titles they are output to the screen using apostrophes to space them.

    in pseudocode

    Code:
    if(title this line and next)
    {
    output name and apostrophe
    }
    else
    {
    output name and endline
    }
    I dont know how to compare or check as I am using getline to read each individual line, should I use two getlines with a one line offset between them?
    I thought the function peek() might work but don't think the characters are there to be read with getline. Any help would be appreciated.


    Besides that I would love to get an audiobook on c++ to listen to while coding or on the bus etc.. are there any free ones or good quality pay ones that don't break the bank.

    Thanks

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    329
    You could use a bool flag? Initially it would be set to false and then each time you read in a line and it is a title, the flag is set to true.
    when you read the next line, if it's a title, it checks if the flag is true (ie, the previous line was a title), if it is true, then you can do whatever you want. Whenever you read a line that isn't a title, you set the flag to false.

    There are probably loads of ways to do this, and people far more experienced than me will probably give you a much better solution, however this is the first that popped into my head.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    20
    Excellent Idea actually.. thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 11:43 AM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 11:50 AM
  3. getline problem
    By Bitphire in forum C++ Programming
    Replies: 5
    Last Post: 10-18-2004, 05:42 PM
  4. getline help
    By ProjectsProject in forum C++ Programming
    Replies: 3
    Last Post: 06-14-2004, 12:12 PM
  5. getline with string class in Borland C++
    By johnnyd in forum C++ Programming
    Replies: 6
    Last Post: 03-08-2003, 02:59 PM

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