Ok so I made the following code which counts how many lines the file has:
Code:
#include <iostream>
#include <ctime>
#include <fstream>
#include <string>
using namespace std;
int LinesCounter(string filename)
{
ifstream b_file(filename);
// new lines will be skipped unless we stop it from happening:
b_file.unsetf(ios_base::skipws);
// count the newlines with an algorithm specialized for counting:
unsigned line_count = count(
istream_iterator<char>(b_file),
istream_iterator<char>(),
'\n');
return line_count;
}
int main()
{
//Starts timing
clock_t begin = clock();
int letter;
cin>>letter;
cin.ignore();
//Obtains the total amount of seconds taken
clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
cout << "\nCongratulations, you took " <<elapsed_secs <<" seconds.";
int NumberOfLines = LinesCounter("Times.txt");
if (NumberOfLines < 10)
{
ofstream a_file ( "Times.txt", ios::app );
a_file<<elapsed_secs <<" seconds" <<endl;
a_file.close();
}
cout<<endl <<endl <<endl <<LinesCounter("Times.txt");
cin.get();
}
Now I need to sort the times out whenever there's a new time. As Jim said I was also thinking about moving each line to a vector/array and sort it out with quick/bubblesort. Now my issue is how do I move each line to an array position?