From: "John Harrison" Newsgroups: alt.comp.lang.learn.c-c++,comp.lang.c++,comp.os.msdos.djgpp References: Subject: Re: Need some help with reading from files Lines: 55 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: Date: Sat, 31 Mar 2001 13:12:23 +0100 NNTP-Posting-Host: 213.104.61.8 X-Complaints-To: abuse AT ntlworld DOT com X-Trace: news2-win.server.ntlworld.com 986040632 213.104.61.8 (Sat, 31 Mar 2001 13:10:32 BST) NNTP-Posting-Date: Sat, 31 Mar 2001 13:10:32 BST Organization: ntlworld News Service To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "Daniel Eliasson" wrote in message news:nj7x6.782$ym1 DOT 6435 AT nntp1 DOT chello DOT se... > Hi, I'm currently working on a small game utilizing a 2d array of int's. > That is, grid[128][128]. > > What I want to do is read a map from a text file. The format of maps is that > every character in the map file is a certain type of int that will be stored > in the grid..... > My problem is, if I want to read the first 128 characters on the first 128 > rows in the text file, how do I get the iostreams to do this? > > I've checked several C++ books, but they never tell me how to manipulate the > place it reads from. Any code/pseudo-code would be greatly appreciated. > Why do you need to manipulate the file position? Despite what others have told you about seekg, it is an error to pass anything to seekg that isn't either the end of file, the start of file or a position previously returned from tellg UNLESS you are dealing with a binary file. You want to use a text file so seekg is going to be of limited use to you (unless you want to write non-portable code). But as I said why manipulate the file position, why not just read the first 128 lines and then 'read' the first 128 bytes of those lines, e.g. ifstream maze("filename"); for (int i = 0; i < 128; ++i) { string line; getline(is, line); string row(line, 0, 128); // first 128 chars // do domething with row } john > Thanks in advance, > -- > // Daniel Eliasson > > PS. I hope you don't mind the crosspost, just trying to maximise my odds of > getting help. > ------------------- > I believe information should be free. > www.gnu.org > >