Say I have a commant.txt file that contains something like:
num_chars logfile.txt
num_lines settings.txt
I haven't included all my code because I think it's not necesary for what I need help with. But if you guys need it in my code understand it better I'll be sure to add it. Anyway...
Below is the code I used to get the first line which is "num_chars logfile.txt"
Then I read it into the string "result". After using that string certain functions I reset it back to an empty string so I can put the next line "num_lines settings.txt" into "result" and use it again. My problem is I can't seem to get the second line. I'm able to get the first line with the while loop below, but I'm not sure how to get the second line. I think it might be because i'm not using fin.get() properly but I'm not sure. My initial thought is that continuing to use fin.get() will continue reading the second line of code, but apparently it does not.
int main()
{
ifstream fin("commands.txt");
string result = "";
char c = fin.get();
while (c != '\n')
{
result += c;
c = fin.get();
}
cout << result << "\n";
result = "";
while (c != '\n')
{
result += c;
c = fin.get();
}
cout << result << "\n";
result = "";