Reading only sections of a text file

This is a discussion on Reading only sections of a text file within the C++ Programming forums, part of the General Programming Boards category; Does anyone know how to do this? Here is my text file: Code: This is a note // This is ...

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Exclamation Reading only sections of a text file

    Does anyone know how to do this?

    Here is my text file:
    Code:
    This is a note // This is the begining of section 1
    
    This comes too
    
    
    This is the second note // This is the begining of section 2
    and it follows
    
    And continues
    I want the program to ask for a number. Once you put in a number it will display the text of a sertain section. It will be able to tell the differences between sections becouse after every section there is two breaks in a row that have no text before them. And depending on what number you put in it displays that section.

    Thanks, August

  2. #2
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Anyone?

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Read dummy lines until your find the line your interested in. std::getline().
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    That would work other than the fact of that if you add lines to you'r notes it would mess everything up!

    Do you have any other ideas?

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Once you put in a number it will display the text of a sertain section
    A section is given a specific number. If you add lines so these numbers are messed up then there's no way to make it regardless of method.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  6. #6
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I see.

    Well, could you give me an example of you'r first idea? I have never heard of
    Code:
    std::getline();
    before.
    Last edited by Queatrix; 04-10-2005 at 04:23 PM. Reason: N/A

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading output into a text file
    By pete212 in forum C Programming
    Replies: 8
    Last Post: 04-23-2008, 05:11 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Reading Character at a time from a text file
    By Giania in forum C Programming
    Replies: 8
    Last Post: 02-25-2006, 02:17 PM
  5. reading from a text file help......
    By jodders in forum C++ Programming
    Replies: 2
    Last Post: 01-25-2005, 11:51 AM

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