A little help reading from files...

This is a discussion on A little help reading from files... within the C++ Programming forums, part of the General Programming Boards category; Well, I know how to read from files one string at a time using istream, but how can I read ...

  1. #1
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210

    A little help reading from files...

    Well, I know how to read from files one string at a time using istream, but how can I read say ... a whole paragraph from a file. To give you an idea of what I'm getting at, let's say I want to write a text adventure, and I want to seperate the text passages into .dat files then read them as whole paragraphs into the game. Of course this can't be done using the simple tutorial version of how to use file streams because strings are truncated at the first whitespace. I don't have code. I'm only looking for theory or useful functions. If anyone can help I'd really appreciate it.
    "The mind, like a parachute, only functions when open."

  2. #2
    Unregistered
    Guest
    Look up using ifstream.read(). It will read more than one line.

  3. #3
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210
    Thanks for the reply.

    I've found that ifstream.get and .getline serve my purposes better though.

    Still not exactly sure what the big difference with .read is but according to MSDN ifstream.read:
    Extracts bytes from the stream until the limit nCount is reached or until the end of file is reached. The read function is useful for binary stream input.
    ..and I'm not working with binaries so who cares
    "The mind, like a parachute, only functions when open."

  4. #4
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210
    ...and I'm not working with binaries so who cares
    LOL my 100th post ends with a "who cares" attitude. Great...
    "The mind, like a parachute, only functions when open."

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    104
    Hi!

    For File I/O check out this tutorial:
    http://www.cpp-home.com/FileIO_tutorial.php

    It's great!
    Ilia Yordanov,
    http://www.cpp-home.com ; C++ Resources

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with reading files
    By glopv2 in forum C Programming
    Replies: 3
    Last Post: 07-31-2007, 11:05 PM
  2. Reading User Defined Files
    By Necrofear in forum C++ Programming
    Replies: 17
    Last Post: 06-30-2006, 12:55 AM
  3. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 10:46 AM
  4. reading files
    By hiya in forum C++ Programming
    Replies: 7
    Last Post: 05-21-2005, 11:40 AM
  5. Need Advice in reading files
    By jon in forum C Programming
    Replies: 4
    Last Post: 10-07-2001, 07:27 AM

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