reading certain parts of text files

This is a discussion on reading certain parts of text files within the C++ Programming forums, part of the General Programming Boards category; using <fstream>, how would I read only certain parts of a text file, and write to only certain parts? For ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    244

    reading certain parts of text files

    using <fstream>, how would I read only certain parts of a text file, and write to only certain parts? For example, if a file looked like this:

    Code:
    ~
    hello
    ~
    welcome
    ~
    Hi %s
    how would I get the program to display "welcome" in the console (or wherever) and ignore the tilde's? Pretty much just a text file with seperators that I want to access certain parts of.

    Any methods that someone would care to explain or provide a link to? Thank

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    let me rephrase:

    say I had some lame textbased RPG where the user info was stored in a file where each piece of info was seperated by a line containing "~". How would I read that data into the program?

    Thanks

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    with ifstream.getline() using '~' as your delimiter. Consult your help files or text for an example.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading in an array of text from a file?
    By suzakugaiden in forum C++ Programming
    Replies: 6
    Last Post: 01-04-2006, 03:17 PM
  2. reading from text file
    By jamez in forum C Programming
    Replies: 3
    Last Post: 11-30-2005, 07:13 PM
  3. Issues reading text files
    By ozzy34 in forum C++ Programming
    Replies: 5
    Last Post: 06-01-2004, 09:15 AM
  4. reading text files
    By stimpyzu in forum C++ Programming
    Replies: 11
    Last Post: 04-17-2004, 08:45 AM
  5. Reading spaces, carrage returns, eof from text files
    By thenrkst in forum C++ Programming
    Replies: 1
    Last Post: 03-11-2003, 05:18 AM

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