Zanaran

Untitled

Mar 5th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <cstdlib>
  5.  
  6. int main()
  7. {
  8. std::ifstream inf("test.din",std::ios::in); //Create file streams
  9. std::ofstream outf("test.dout",std::ios::out);
  10.  
  11. unsigned int coln = 20; //Max columns
  12. unsigned int rown = 10; //Max rows
  13. int y = 0; //Current row
  14. int x = 0; //Current column
  15. char tileset[] = { '!', '@', '#', '$', '%', '^', '&', '*'};
  16.  
  17. std::vector< std::vector<int> > v;
  18.  
  19. v.resize(coln, std::vector<int>(rown, 0)); //Expand it to the max columns and rows
  20.  
  21. //READING THE INPUT
  22.  
  23. //I'm dealing with a "vector of vectors," so it gets two for loops for each dimension.
  24.  
  25. for(y = 0; y < rown; ++y) //Fills out columns...
  26. {
  27. for(x = 0; x < coln; ++x) //Fills out rows...
  28. {
  29. if (!(inf.eof())) //when the file hasn't ended
  30. {
  31. inf >> v[x][y]; //put file info inside of the vector
  32. }
  33. else
  34. {
  35. v[x][y] = 0; //otherwise fill the blank spaces with 0
  36. }
  37. //std::cout << v[x][y] << ' ';
  38. }
  39. //std::cout << std::endl;
  40. }
  41.  
  42. //WRITING THE OUTPUT
  43.  
  44. for(y = 0; y < rown; ++y)
  45. {
  46. for(x = 0; x < coln; ++x)
  47. {
  48. outf << tileset[v[x][y]] << ' ';
  49. }
  50. outf << std::endl;
  51. }
  52.  
  53. system("PAUSE");
  54. inf.close();
  55. outf.close();
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment