strings

This is a discussion on strings within the C++ Programming forums, part of the General Programming Boards category; say you have 3 rows of text in a file but you only want to extract say the second line ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    142

    strings

    say you have 3 rows of text in a file but you only want to extract
    say the second line of text. is there a way to do this and is the a way to store different groups of text and then extract them later using some sort of search method?????????????????

    and yes i have searched all day and havn't found anything so if anyone knows a way pleasse tell me........
    WhAtHA hell Is GoInG ON

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    seekg() is not going to help with text files unless you already know the exact position of the start of the string, and that's not very likely to be the case with most text files where each line is a different length.

    wart101: the only way to extract a specific line is to read the whole file one line at a time, counting the lines as they are read. Just put getline() in a loop and you wil get what you want.

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    Hmm... I though seekg() had a method to specify the start of lines. My apologies.
    Sent from my iPadŽ

  5. #5
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    You could just read in the file and save the lines you want to a vector by using push_back(...). Or you could store the whole file (vector) and just keep a record of what lines (indexes) in the file you want.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  3. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 07:37 AM
  4. damn strings
    By jmzl666 in forum C Programming
    Replies: 10
    Last Post: 06-24-2002, 03:09 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 12:23 PM

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