file io troble

This is a discussion on file io troble within the C++ Programming forums, part of the General Programming Boards category; i am creating a computergame atm. a MMORPG for 50 players a time. but i want to read a part ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,488
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 04: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, 09:46 AM
  5. File IO with .Net SDK and platform SDK
    By AtomRiot in forum Windows Programming
    Replies: 5
    Last Post: 12-14-2004, 09:18 AM

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