Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <vector>
- using namespace std;
- int main()
- {
- vector<vector<int> >matrix;
- ifstream file;
- file.open("/home/minhaz/matrix.txt");
- int row = 0;
- int col = 0;
- string line;
- while(!file.eof())
- {
- vector<int> row_data;
- getline(file, line);
- stringstream sstream;
- sstream << line;
- col = 0;
- int val;
- while(sstream >> val)
- {
- row_data.push_back(val);
- col++;
- }
- matrix.push_back(row_data);
- row++;
- }
- cout << "The matrix is " << row << " x " << col << endl;
- for(int r=0; r<matrix.size(); r++)
- {
- for(int c=0; c<matrix.at(r).size(); c++)
- {
- cout << matrix.at(r).at(c) << " ";
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement