Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

i have a problem reading the data in this file.

$
0
0
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <stdlib.h>

using namespace std;

struct detail			//CREATING A STRUCTURE
{
		int lane;
		long num;
		string name;
		string nat;
		float time;				
};

	float convert(string &minutes, string &seconds)	//THIS FUNCTION IS TO CONVERT THE WHOLE TIME TO SECONDS
{
	float sec;
	float min;
	float result;
	sec = stof(seconds);
	min = stof(minutes);
	result = (min*60) + sec;	//60 WAS USE AS THE NUMBER OF SECONDS FOR ONE MINUTE
	return result;
}

void dataForm (detail Record[],ifstream &myFile)	//FUNCTION TO READ THE ENTIRE DETAILS FROM THE FILE
{
string buff;
stringstream playerRecord;
getline(myFile,buff);
for( int i = 0; i < 8; i++)
{
getline(myFile,buff);
playerRecord<< buff;
getline(playerRecord, Record[i].lane, " "); 
getline(playerRecord, Record[i].num, " ");	
getline(playerRecord, Record[i].name, " ");	

string minutes;
string seconds;
float conv;
string temp;
getline(playerRecord, minutes, '.');	//READING THE MINUTES FROM THE TIME SECTION
getline(playerRecord, seconds, " ");	//READING THE SECONDS FROM THE TIME SECTION
Record[i].time = convert(minutes,seconds);	
playerRecord.clear();	//clear the temporal data
}
}
int main ()
{
detail Record[21]; 
ifstream myFile;
myFile.open("osaka.txt");
dataForm (Record,myFile); //function that for that reads the data now called
myFile.close();
cout<<endl;
	for( int i = 0; i < 7; i++)
		for (int i = 0; i <8; i++)
{
	 	   cout<<"    " <<Record[i].lane <<"    "<< Record[i].num<< Record[i].name <<"    "<<Record[i].nat<<"    ";
	   cout<<"    "<<Record[i].time<<"    "<<endl;
}	

}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>