473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Input file pointer manipulation

Hello All,

I wanted came here to get some advice on reading an input file where I will have to ignore some of the text. Here is the sample text file:

SIZE: 4 ROWS, 4 COLUMNS
SCORE: 0 0
----
----
----
----

For now, I'm just trying to read the integers on the first and second line. The next step is reading the "-" into a 2-D array that I have declared, but I haven't gotten that far yet. (However, if anyone has any hints how to read this into a 2-D they are readily welcome!)

Here is my code for reading the input file: (just a snippet of code in my main function)
Expand|Select|Wrap|Line Numbers
  1.  if (myfile.is_open())
  2.     {
  3.        while (! myfile.eof() )
  4.        {
  5.  
  6.          myfile.seekg (7);
  7.          rows = myfile.tellg();
  8.          cout << "The number of rows: " << rows << endl;
  9.  
  10.          myfile.seekg(15);
  11.          columns = myfile.tellg();
  12.          cout << "The number of columns: " << columns <<endl;
  13.  
  14.          myfile.seekg(31);
  15.          PlayerA = myfile.tellg();
  16.          cout << "Player A has a score of: " << PlayerA << endl;
  17.  
  18.          myfile.seekg(33);
  19.          PlayerB = myfile.tellg();
  20.          cout << "Player B has a score of: " <<PlayerB << endl;
  21.  
  22.          myfile.seekg(0, ios::end);
  23.  
The problem is I get the pointer position, which is correct because tellg() returns the pointer position. How can read the value in the pointer position? Any suggestions are welcome. TIA!
Oct 9 '07 #1
1 3367
weaknessforcats
9,208 Expert Mod 8TB
(the class declaration)
You seekg to the value returned by tellg. Your next read will start there.
Oct 9 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Gert Van den Eynde | last post by:
Hi all, Could you give me some pointers on how to parse a text input file in C++? Most will be config-file style input (keyword = data), but some maybe 'structures' like material{ name = n,...
7
by: W. Van Hooste | last post by:
Hello, I'm writing a program to display somme values as nice X graphics for a special purpose. Under here is part of my main code and part of the code to gather the sample data. the sample data...
21
by: deepak | last post by:
hi folks I have a pointer to a file. If i increment the pointer, where will it point. I could not find the problem in the FAQs. Thanks in advance Deepak garg
5
by: Apollyon | last post by:
I'm trying to figure out if there's a function that takes a file pointer (FILE *) and will return a HANDLE type ... I'm trying to modify some code and I've looked everywhere to no avail. Thanks...
3
by: Don Pasquale | last post by:
The following function intends to delete "numberoflines" lines from a text file, named "s" (string pointer) and pointed to by file pointer "fp", starting from line "line". Now, the function...
9
by: Abhishek | last post by:
Hello everybody, I am reading a file into a char array. Because of which we cannot give array size in GBs of data. Is there a technique through which i can cast a file pointer to char pointer...
5
by: jwright | last post by:
I have decided to use a struct to collect my data. The input file is comma dilineated between almost all of the fields. Here is the code I have so far and a sample input and output file. ...
5
by: jslee99a | last post by:
hello I use visual basic 6.0. I want to read file twice. First i read file then i don't know how to move the file pointer to the start point. i don't want to close file and reopen. ...
1
by: Moot | last post by:
The scenario is that I am processing a large text file and moving each line to one of a number of other files based on some criteria. I have an array of file pointers with writable files. I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.