Expand|Select|Wrap|Line Numbers
- <matrix>
- rows = 2
- cols = 2
- 1 2
- 2 4
- </matrix>
below is my code..
and i checked that this doesnt work...
and apparantly someone told me that this is in c programmin style..
could ya help me design a method to read the file in a c++ programming way?
i have done my work.. and this is just exercise from the textbook i am learning c++ from.. unfortunately it doesnt have the solutions.. so i am lost on how to do it.. check my other postings to see that i have actually done my work and this is not homework.. so could someone help me please????
Expand|Select|Wrap|Line Numbers
- void Matrix::readMatrixFile(string FILENAME)
- {
- const string filename(FILENAME);
- ifstream file(filename.c_str());
- string line;
- if (getline(file, line) && line == "<matrix>")
- {
- if (file >> line /* "rows" */ && file >> line /* "=" */ && file >> row && getline(file,line) /* ; */)
- {
- if (file >> line /* "cols" */ && file >> line /* "=" */ && file >> col && getline(file,line) /* ; */)
- {
- for (int r = 0; r < row; r++)
- {
- for (int c = 0; c < col; c++)
- {
- int value;
- if (file >> value)
- {
- m[r][c] = value;
- }
- }
- cout << endl;
- }
- }
- }
- }
- }