when i write this array into the c++ debugger i just get a bunch of zero's set up in array form. the columns and rows are all right but i don't get the right values. What exactly do i have to do to get all the same integers?
yourfile >> FileRows ;
int rows = atoi( FileRows.c_str() ) ;
yourfile >> FileCols ;
int cols = atoi( FileCols.c_str() ) ;
yourfile >> Array ;
cout << "The 2-dimensional Array you have created is" << rows << " rows by " << cols << " columns." << endl ;
for ( k = 0 ; k < rows ; k++ )
{
for ( l = 0 ; l < cols ; l++ )
{
matrix[k][l] = atoi (Array.c_str() ) ;
cout << static_cast<int>(matrix[k][l]) << "\t" ;
}
cout << endl ;
}
yourfile.close() ;
}
Why don't just yourfile >> rows >> cols; ? they are numbers, so read them as numbers.
If you insist on doing the conversion use strtol or an stringstream and check for errors.
how do you use strtol? and also this is not supposed to be printed in "yourfile" rather in "cout" all those 42's must be all random numbers that were stored in ASCII in an output file.