Hi, i just don't get why this isn't working.
It is supposed to read from the end of a .txt and up, until it hits the first space but
it just keeps repeating the last character in the text file ip.txt
Any help is much appreciated.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
string ip = "a";
char chr;
ifstream iptilvar;
iptilvar.open ("ip.txt"); //open filestram
for (int i=-1;ip!=" ";i--) //keep reading until a space is found
{
iptilvar.seekg (i, ios::end); //set the getpoint to eof -i
getline (iptilvar,ip);
chr = ip[0]; //get the first character of the string called ip
ip = chr;
cout<< ip;
}
iptilvar.close ();
return 0;
}