------------------------------------------------------
Name: Qasim Zafar
Address: Khanewal, Block 14
Date: 26-01-2012
Destination: Lahore
Flight No: 241
Seat: 76
------------------------------------------------------
This is the text file from where I want to copy some info to some char arrays.
like Name[]; Address[];
Now I need only the last column information, my question is, is there any way through which I could get only the last column..........by using seekg();
I wouldn't use seekg(). I would read in each line in the file with a getline() and then use find() to find the ":" and then save off one plus that value to the end of the string (make sure you check boundaries). That would get you the second/last column.
#include <fstream>
#include <iostream>
int main()
{
char tmp[256] = {0};
std::ifstream in("list.txt");
in.seekg(0,std::ios_base::end);
int end = in.tellg();
int marker = end - 2; // just in case the file ends with a line break
while(--marker)
{
in.seekg(marker,std::ios_base::beg);
if(in.peek() == 0x0A || in.peek() == 0x0D)
{
in.seekg(++marker,std::ios_base::beg);
in.read(tmp,end-marker+1);
break;
}
}
std::cout << tmp << std::endl;
}