Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <random>
- 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
- 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
- {
- if (!(inf.eof())) //when the file hasn't ended
- {
- inf >> v[x][y]; //put file info inside of the vector
- }
- else
- {
- v[x][y] = 0; //otherwise fill the blank spaces with 0
- }
- x++;
- 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;
- //WRITING THE OUTPUT
- while (true)
- {
- int r = 0; //I need this because...
- r = v[x][y]; //...I have to use the value from the vector...
- switch (r) ///...in a switch statement
- {
- case 0:
- {
- outf << '!';
- }
- break;
- case 1:
- {
- outf << '@';
- }
- break;
- case 2:
- {
- outf << '#';
- }
- break;
- case 3:
- {
- outf << '$';
- }
- break;
- case 4:
- {
- outf << '%';
- }
- }
- outf << ' '; //whitespace for readability
- x++;
- if (((y == rown) && (x == coln))) break;
- if (x == coln)
- {
- x = 0;
- y++;
- outf << std::endl;
- }
- }
- system("PAUSE");
- inf.close();
- outf.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment