#include <iostream>
#include <fstream>
using std::ifstream;
#include <cstdlib> // for exit function
//this program will read in 2 matrices and store them in two 2d arrays
//the text file includes text other then the matrices
int main()
{
ifstream indata;
int num;
indata.open("matrixFile.dat"); // opens the file
if(!indata) { // file couldn't be opened
cerr << "Error: file could not be opened" << endl;
exit(1);
}
indata >> num;
while ( !indata.eof() ) { // keep reading until end-of-file
//this is where each number will get stored into the array
indata >> num; // sets EOF flag if no value found
}
indata.close();
cout << "End-of-file reached.." << endl;
return 0;
}
here is what a sample .dat file will look like
first matrix: 34 45 23 85 93 72 85 37 26 second matrix: 34 66 43 33 11 33 99 44 56
overall, what im looking for at this point is some manipulation code for reading in files that will ignore whitespace and characters that aren't digits, and if theres a way to read in digits as double digits.
thanks!

New Topic/Question
Reply



MultiQuote






|