This way you can get the value of any column in the file as string.
If you need the date in some other format you have to convert it.
Code:
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
using namespace std;
// string GetdateValue(int column,string line) {
string GetColumnValue(int column,string line) { // use meaningful names
string temp;
stringstream sstr(line);
for( int i = 0; i < column; ++i )
getline(sstr,temp,','); // read into temp separated by ','
return temp; // return last read value
}
int main() {
ifstream input_file("Log_05.txt");// is a scv file have many coulmn first column of it is the date
string line;
int count;
string date_str; // they are all the same
string time_str; // for demonstration
if ( input_file.fail ()) {
cout << "Error opening file.";
}
else {
count = 0;
while( getline(input_file,line) && count <= 1447) { // while there is no error and linecount < 1448 if you want it like this
if ( count == 20 ) { // get date from line 20
date_str = GetColumnValue( 1, line ); // date is col 1
time_str = GetColumnValue( 2, line ); // time is col 2
}
count++; // Increment the count, to go to the next line
}
cout << "date is '"<< date_str << "' time is '" << time_str << "'" << endl;
}
return 0;
}