Jump to content
  • Advertisement
Sign in to follow this  
gingsi

VC++ 2005 file processing...please help me...

This topic is 3906 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In fact I have a txt file (or dat file), contain a list to do some operations. The list is like this: date open high low close volume turnover 2003-12-18 4.533 4.582 4.283 4.508 1588699385 7063136408 2003-12-19 4.508 4.632 4.458 4.582 557293890 2510226274 . . . . . . Here is part of my program, if I do not use the function getline(), what other function I can use to save the parameter into different arrays? I know there are other function such as read and get, but I do not know if they can be used as this purpose. void readdata() { string line; ifstream myfile("abc.txt"); if(myfile.is_open()) { while(!myfile.eof()) { getline(myfile,line); } } myfile.close(); } How should I modify my program? Thank you for your kindly help. [Edited by - gingsi on January 15, 2008 10:44:42 AM]

Share this post


Link to post
Share on other sites
Advertisement
You may find the >> ifstream operator useful. Here is a simple usage example that is not very robust:


void readdata()
{
string date;
float open = 0.0;
float high = 0.0;
float low = 0.0;
/* ... etc. for the rest of your data fields */

ifstream myfile("abc.txt");

if (myfile.is_open())
{
myfile >> date;
myfile >> open;
myfile >> high;
myfile >> low;
/* ... etc. for the rest of your data fields */

myfile.close();
}
}



The above will read the data fields of the first line of the text file into the corresponding variables. If you want to use the above example, you will need to add a loop to read all lines as well as incorporate your data structure of choice for storing the data. Note that you may need to ignore the first line in the file since it is labeling information rather than actual data. Hope this helps.

Share this post


Link to post
Share on other sites
Thank you very much for your help. However, I have tried to use operator >> before. It does not work, the error shown is:

C2679:binary '>>': no operator found which takes a right-hand operand of type 'float'(or there is no acceptable conversion)

By the way, the program is writing as window form application. As I am writing a GUI program, does this affect for the use of >> operator?
Thank you very much.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!