Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cstdlib>
- void read(std::string name)
- {
- std::fstream file;
- file.open(name, std::ios::in | std::ios::out);
- if(file.is_open() == 0)
- {
- std::cout << "Problem with reading a file." << std::endl;
- exit(0);
- }
- else
- {
- int sizeY;
- int sizeX;
- file >> sizeY >> sizeX;
- int **ary = new int*[sizeY];
- for(int i = 0; i < sizeY; ++i)
- {
- *(ary + i) = new int[sizeX];
- }
- int data;
- for(int i = 0; i < sizeY; i++)
- {
- for(int j = 0; j < sizeX; j++)
- {
- file >> data;
- *(*(ary + j) + i) = data;
- }
- }
- std::cout << "file content:" << std::endl;
- for(int i = 0; i < sizeY; i++)
- {
- for(int j = 0; j < sizeX; j++)
- {
- std::cout << *(*(ary + j) + i);
- std::cout << " ";
- }
- std::cout << std::endl;
- }
- }
- file.close();
- return;
- }
- int main()
- {
- read("file.txt");
- //tutaj ma isc dalsza czÄĹÄ zadania
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement