So you need to report the distance from the end of the file of the last occurrence of the
'.'
.
Try
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
ifstream fin("t.txt");
string line;
int lines = 0;
int characters = 0;
int found_line = 0;
size_t found_pos = string::npos;
while (true)
{
if ( ! getline(fin, line) ) break;
auto pos = line.find_last_of('.');
if ( pos != string::npos)
{
found_line = lines;
found_pos = (characters + pos);
}
++lines;
characters += line.length();
}
if ( found_pos != string::npos)
{
found_line = (lines - 1 - found_line); found_pos = (characters - 1 - found_pos); cout << "line " << found_line << "\n";
cout << "pos " << found_pos << "\n";
}
return 0;
}