Hi guys I seem to be stuck in an infinite loop and can't figure out for the life of me why it is occuring,
I'm reading from a file I tested and made sure that personStart
equals 447
,also with some debugging I can confirm in.tellg()
equals 7
it seems to work first time around but after it prints all the indexes from 8
to 447
it gets stuck in an infinite loop and keeps printing -1
(the file pointers value)
**edit when I remove the second while loop it still works fine and terminates,so it's not a problem with the first while loop( also not a duplicate and no idea why it would be downvoted)
Ok guys I'll edit the question and code so it's complete but I'm just quite annoyed with this question been marked a duplicate as the above question doesn't help me in the slightest so I've created a txt file to be randomly accessed using indexes now I have run into a problem when trying to read from that txt file I get stuck in an infinite loop,I've tested other code in inside a nested while loop and it runs perfect,if someone could just suggest why it may be happening and what is wrong here I will be more than grateful.
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <sstream>
using namespace std;
int main()
{
vector<Person> people;
map<int,Index> index;
stringstream ss;
ifstream in;
in.open("randomAccess.txt");
int hello = 6;
while(!in.eof()){
string size;
getline(in,size,':');
string personStartString;
getline(in,personStartString,':');
int personStart;
ss << personStartString;
ss >> personStart;
ss.str(string()); // clear string stream
ss.clear();
while(in.tellg() < personStart){
string indexString;
getline(in,indexString,':');
int indexNumber;
ss << indexString;
ss >> indexNumber;
cout << in.tellg() << endl;
if ( in.fail() ){
cout << "failed" << endl;
}
}
}