Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. vector<vector<int> >matrix;
  11.  
  12. ifstream file;
  13. file.open("/home/minhaz/matrix.txt");
  14.  
  15. int row = 0;
  16. int col = 0;
  17.  
  18. string line;
  19.  
  20. while(!file.eof())
  21. {
  22. vector<int> row_data;
  23.  
  24. getline(file, line);
  25.  
  26. stringstream sstream;
  27. sstream << line;
  28.  
  29. col = 0;
  30. int val;
  31. while(sstream >> val)
  32. {
  33. row_data.push_back(val);
  34. col++;
  35. }
  36.  
  37. matrix.push_back(row_data);
  38.  
  39. row++;
  40. }
  41.  
  42. cout << "The matrix is " << row << " x " << col << endl;
  43.  
  44. for(int r=0; r<matrix.size(); r++)
  45. {
  46. for(int c=0; c<matrix.at(r).size(); c++)
  47. {
  48. cout << matrix.at(r).at(c) << " ";
  49. }
  50. cout << endl;
  51. }
  52.  
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement