very good point chevril I will change my code to do that =)
thanks for the help I also have run into another problem with the following block of code,
I added a get info() function to get the peoples info but it seems to be stuck in an infinite loop that keeps printing id and daysMissed and also for some reason to my confusement does not print the first variable name
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
bool getInfo(){
cout << "in this block " << endl;
ifstream in;
string fileName = "missed.txt";
stringstream ss;
in.open(fileName);
if(!in.is_open()){
cout << "not open" << endl;
return false;
}
string name;
string id;
string daysMissed;
while(missed){
getline(in,name,':');
ss << name;
getline(in,id,':');
ss << id;
getline(in,daysMissed);
ss << daysMissed;
cout << name << " " << id << " " << daysMissed << endl;
}
in.close();
cout << ss.str();
}
|
I did not expect this I used getline with the delimiter ':' to get up to the : character then it gets thrown away then I said getline() again with : as the delimiter so it reads up to ':' and throws away the : then I say getline again with no delimiter so I would expect that getline to be to consume the next line but I seem to have to add cin.get(),
when I add cin.get()
it seems to work but not in the way I want or expect it to it prints the first name of the textfile then when end the program thats WHEN it prints out all the names of the file but it doesn't stop there it then prints ID and missedDays a couple more times before ending
here is the output before I terminate the program for some reason the program doesn't terminate by itself which it SHOULD but instead prompts me for infinite input
enter employee name and ID
bill 9 3
enter days employee has missed
enter employee name and ID
eva 8 2
enter days employee has missed
in this block
jeff 6 1
then when I terminate the program forcefully this is the output
in this block
jeff 6 1
steve 6 2
jim 66 6
brock 88 3
sarah 14 4
lisa 88 4
brett 7 5
matt 6 2
darren 4 5
conor 8 2
tima 5 5
jessica 4 4
bill 9 3
eva 8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
thanks