Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFile Reading 1

Status
Not open for further replies.

sabakrish

Programmer
Jul 30, 2001
6
LK
Hi,every body,
I am working with MFCAppWizard.exe application. Now I have a problem in reading a data file. My data file is of the form:
100 300
400 500
400 700
250 500
... ...
... ...
suppose that the two coloums in the data file represents x and y coordinates respectively.

problem:
while reading this data file I have to store in two different arrays, say x[],y[].???
adn I have to plot a graph using these coordinates.
plesase let me know how to do this.As early as possible.

Advance thanks

sabakrish



 
Personally, I'd open the file up with ifstream, then use a string to read a line at a time:

ifstream infile("filename.txt"); //file to read from
string data, xdata, ydata; //strings for retrieving data
vector<int>x, y; //vectors for storing data
while(infile){
getline(infile, data);
xdata = data.substr(0, data.find(&quot; &quot;)); //get the x portion
ydata = data.substr(data.find(&quot; &quot;)); //get the y portion
x.push(atoi(xdata.c_str()); //add x value as integer to vector
y.push(atoi(ydata.c_str()); //same for y value
}

I won't swear this is bug-free, but it should get you going in the right direction.
 
that one also work:
getline>>infile;
getline>>data;

John Fill
1c.bmp


ivfmd@mail.md
 
Hello

The class String is not support to MFC application.
when I copied your code and paste within the onDraw()
member function under CView class(MFCWizardApp.exe), It showed 23 errors and type vecotor,String and ifstream are not accepted(&quot;undeclare error&quot; message). ifstream is used in console appication and is not recommeded to MFC!!!!
Please suggest an alternative idea using CFile class or support to MFC applicaton.


Thank you for your response.
 
why exactly are you using MFC? You don't need to in this situation, why use CFile when you don't have to
 
Anybody,Please reply to my post as early as possible. It is an urgent, please help me.

Please Note: stukA's suggetion is not compiled under MFCAppWizard.exe(the reason is indicated in my previous post). If you do not understand my problem please don not hesitate to contact me.


My advance Thanks

sabakrish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top