Thread: file io troble

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    1

    file io troble

    i am creating a computergame atm.
    a MMORPG for 50 players a time.
    but i want to read a part of the map out of a file.
    i am using the file iostream for this.
    but is there a way to read it line for line??
    and if i only need line 50 that he will leave the rest and only read line 50??

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well the short answer is to use a loop to count through the lines until you get the one you want.

    A longer answer is to read every line of the file, and build up an index of 'tell' positions for each line, then you can 'seek' to any given line at a later time.

    Unless the file is excessively large, then reading the whole file into memory (say a std::vector<std::string> of lines) is an alternative.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. File IO with .Net SDK and platform SDK
    By AtomRiot in forum Windows Programming
    Replies: 5
    Last Post: 12-14-2004, 10:18 AM