#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
usingnamespace std;
int main()
{
int rows = 0, cols = 0;
string line, item;
ifstream file( "DB.txt" );
while ( getline( file, line ) )
{
rows++;
if ( rows == 1 ) // First row only: determine the number of columns
{
stringstream ss( line ); // Set up up a stream from this line
while ( ss >> item ) cols++; // Each item delineated by spaces adds one to cols
}
// .... // // Do any processing on a line here
cout << "Line read is " << line << endl;
}
file.close();
cout << "\nFile had " << rows << " rows and " << cols << " columns" << endl;
}
Line read is 07MWSKN 765 2 34123
Line read is 07MWZBW 56 197 165
Line read is 07MWZDW 765 234 123
File had 3 rows and 4 columns