I need to know the number of columns from a text file with floats.
I\'ve made like this to know the number of lines:
inFile.open(pathV);
// checks if f
Given a line you have read, called line
this works:
std::string line("189.53 58.867 74.254 72.931 80.354");
std::istringstream iss(line);
int columns = 0;
do
{
std::string sub;
iss >> sub;
if (sub.length())
++columns;
}
while(iss);
I don't like that this reads the whole line, and then reparses it, but it works.
There are various other ways of splitting strings e.g. boost's
See previous post here