reading txt file. How do I FAST read the data?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Thread: reading txt file. How do I FAST read the data?

Threaded View

  1. #1
    Join Date
    Feb 2011
    Posts
    6

    reading txt file. How do I FAST read the data?

    Hi everybody
    I wrote a program that reads from txt. But it takes to much time to read the data. My txt file contains following information:
    =====Traces=====
    10:18:18.176 -> 52 1 0 -1 -690 1000 0 100 0 690 1000 0 100
    10:18:18.285 -> 52 1 0 -1 -490 1000 0 100 0 6904 1000 0 100
    10:18:18.394 -> 52 1 0 -1 -690 1000 0 100 0 690 1000 0 100
    ...
    I have to convert this numbers to integer. my function does it like this:

    after I read the position of whitespaces

    leerzeichen is an array that contains a position of whitespaces of the line(zeile).
    ...
    Code:
    ostringstream sLength,sType,sTimestamp,sX1,sX2,sY1,sY2,sZ1,sZ2,sDy1,sDy2,sConf1,sConf2;
    				for(i=0;i<sizeof(zeile);i++){ // TAKES TO MUCH TIME!!!
    					if(i>leerzeichen[1] && i<leerzeichen[2])
    						sLength<<zeile[i];
    					else if(i>leerzeichen[2] && i<leerzeichen[3])
    						sType<<zeile[i];
    					else if(i>leerzeichen[3] && i<leerzeichen[4])
    						sTimestamp<<zeile[i];
    					else if(i>leerzeichen[4] && i<leerzeichen[5])
    						sX1<<zeile[i];
    					else if(i>leerzeichen[5] && i<leerzeichen[6])
    						sX2<<zeile[i];
    					else if(i>leerzeichen[6] && i<leerzeichen[7])
    						sY1<<zeile[i];
    					else if(i>leerzeichen[7] && i<leerzeichen[8])
    						sY2<<zeile[i];
    					else if(i>leerzeichen[8] && i<leerzeichen[9])
    						sZ1<<zeile[i];
    					else if(i>leerzeichen[9] && i<leerzeichen[10])
    						sZ2<<zeile[i];
    					else if(i>leerzeichen[10] && i<leerzeichen[11])
    						sDy1<<zeile[i];
    					else if(i>leerzeichen[11] && i<leerzeichen[12])
    						sDy2<<zeile[i];
    					else if(i>leerzeichen[12] && i<leerzeichen[13])
    						sConf1<<zeile[i];
    					else if(i>leerzeichen[13])
    						sConf2<<zeile[i];
    				}
    				string temp=sLength.str();
    				t_length=atoi(temp.c_str());
    				temp=sType.str();
    				t_type=atoi(temp.c_str());
    				temp=sTimestamp.str();
    				t_timestamp=atoi(temp.c_str());
    				temp=sX1.str();
    				t_x1=atoi(temp.c_str());
    				temp=sX2.str();
    				t_x2=atoi(temp.c_str());
    				temp=sY1.str();
    				t_y1=atoi(temp.c_str());
    				temp=sY2.str();
    				t_y2=atoi(temp.c_str());
    				temp=sZ1.str();
    				t_z1=atoi(temp.c_str());
    				temp=sZ2.str();
    				t_z2=atoi(temp.c_str());
    				temp=sDy1.str();
    				t_dy1=atoi(temp.c_str());
    				temp=sDy2.str();
    				t_dy2=atoi(temp.c_str());
    				temp=sConf1.str();
    				t_conf1=atoi(temp.c_str());
    				temp=sConf2.str();
    				t_conf2=atoi(temp.c_str());
    the problem is that sstream, it takes along time. How can i fix that problem? Any ideas?

    Thank you
    Last edited by diman65; February 7th, 2011 at 06:10 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center