I have a data file "1.dat" which has 4 columns and 250 rows.
I need to read each row and process it such as to multiply two columns [col1 and col2].
Can you suggest a way to do this please?
I have to use C++.
I have a data file "1.dat" which has 4 columns and 250 rows.
I need to read each row and process it such as to multiply two columns [col1 and col2].
Can you suggest a way to do this please?
I have to use C++.
http://www.cplusplus.com/doc/tutorial/files/ Here's a few tips on how to read a file using C++, after that you're going to need to cast a string into an integer or float depending.
 
    
    Assuming the file has delimited data, you will probably:
ifstream to open the filestd::getline( ifstream, line ) to read a line. You can do this in a loop. line should be of type std::stringTo store the read data you could use vector< vector< double > > or some kind of matrix class.
with vector<vector<double> >
ifstream ifs( filename );
std::vector< std::vector< double > > mat;
if( ifs.is_open() )
{
   std::string line;
   while( std::getline( ifs, line ) )
   {
       std::vector<double> values;
       std::istringstream iss( line );
       double val;
       while( iss >> val )
       {
          values.push_back( val );
       }
       mat.push_back( values );
   }
}
