Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- int main()
- {
- std::fstream inf("test.d", std::ios::in); //Create file streams
- std::ofstream outf("test.dlvl", std::ios::out);
- unsigned int coln = 10; //Max columns
- unsigned int rown = 9; //Max rows
- int y = 0; //Current row
- int x = 0; //Current column
- char tileset[] = { '!', '@', '#', '$', '%' };
- std::vector< std::vector<int> > v; //Initialize 2D vector
- v.resize(coln, std::vector<int>(rown, 0)); //Expand it to the max columns and rows
- //READING INPUT
- while (!(y == rown && x == coln)) //while the max boundaries haven't been reached
- {
- v[x++][y] = !inf.eof() ? inf.get() : 0;
- if (y == rown && x == coln)
- break; //once the max boundaries have been reached, exit
- if (x == coln) //new line
- {
- x = 0; //resets the column position, and
- y++; //moves the row position down one line
- }
- }
- y = 0; //reset
- x = 0;
- inf.close();
- //WRITING THE OUTPUT
- while (true)
- {
- outf << tileset[v[x++][y]] << ' '; //whitespace for readability
- if ((y == rown && x == coln))
- break;
- if (x == coln)
- {
- x = 0;
- y++;
- outf << std::endl;
- }
- }
- outf.close();
- return 0;
- }
Add Comment
Please, Sign In to add comment