Hello, I'm trying to read data from a file of 6 lines, storing the values of the fields found in each line in 6 different vectors, knowing that this number of fields is variable. Therefore, I assumed I needed a condition to check when the end line is reached, but I'm not sure I've found anything that actually works.
My idea was to count the number of spaces between fields in a line and, then, to read this amount of times + 1 from it. Unfortunately, in doing so I end up using getline() together with tellg() and seekg(), which cause problems by cutting off some characters. I tried different times, but I still don't quite know why this happens nor how I would go to solve it. Any suggestion on the correct implementation of this particular approach or an analogous one in respect to the original problem is greatly appreciated. Here's what I tried to do for the first line, same things for the others:
Thank you, that was exactly what I was looking for. Can I ask you one more thing? I had to use every time a different istringstream variable, is there a way to reuse the same, instead? I found out I should use mystring.str("") and clear.mystring(), but still when I try to open the line again it gives me the following error:
no match for call to '(std::istringstream {aka std::basic_istringstream<char>}) (std::string&)'|