+ 1
C++ File Processing and sstream
I just don't understand what is going with this program (here's the program) https://pastebin.com/WtXsNmhM First, I want to understand the relationship with #include sstream and stringstream ss(line); Second, what is while (!infile.eof()) doing? Does it mean to execute the functions below if the input file is not at the end? Third, what is the point of string line; along with it's relationship to stringstream ss(line); Fourth, what is happening with the while (getline(ss, token, ' ')) (Even, though I highly doubt getting an answer, it was sure helpfult to think about it...)
1 Answer
+ 6
<sstream> is the header which provides string stream functionalities.
.eof() method in fstream checks if the file read from is at the end of line. The context 'while (!infile.eof())' implies : While the file still has not been read till the end of line, execute this block of code. Tl;dr, yes, you are correct.
When you are doing stringstream ss(line), you are declaring object ss of stringstream, initializing it using value stored in line.
Fourth... dk lol. Haven't really read the code due to bad net conn. That said, while (getline(//something)) usually can be read as 'while the input stream is still not empty, get an entire line of input from the stream and store it into a variable.