Short answer
There doesn't exist a native C++ function that would satisfy your needs.
A simple workaround
Assuming that each row contains the same amount of columns and columns can't be empty, one simple possibility would be to walk through the string of the first row and check each character if it matches ' ' or '\t' and then increment a counter unless the previous character was also a space character (i.e. multiple space characters were used to delimit a column)
Please note: This assumes additionally that there exists at least one column in the row and the line does not end with delimiters.
int countColumns(string row){
int numberOfColumns=1;
bool previousWasSpace=false;
for(int i=0; i<row.size(); i++){
if(row[i] == ' ' || row[i] == '\t'){
if(!previousWasSpace)
numberOfColumns++;
previousWasSpace = true;
} else {
previousWasSpace = false;
}
}
return numberOfColumns;
}
Example
Calling
cout << countColumns("1 2 3 4") << endl;
cout << countColumns("1 2 3 4\t\t5") << endl;
returns
4
5