Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. int main()
  7. {
  8.     class Map
  9.     {
  10.     public:
  11.         Map()
  12.         {
  13.         }
  14.        
  15.         bool Load( const std::string& flnm )
  16.         {  
  17.             std::ifstream inpt;
  18.             inpt.open( flnm.c_str( ) );
  19.            
  20.             if( !inpt.is_open( ) )
  21.             {
  22.                 return false;
  23.             }
  24.            
  25.             int w = 0, h = 0;
  26.            
  27.             inpt >> w >> h;
  28.            
  29.             std::vector< std::vector<int> > mp_vec (w, std::vector<int>( h ));
  30.            
  31.             for( int i = 0; i < w; i++ )
  32.             {
  33.                 for( int j = 0; j < h; j++ )
  34.                 {
  35.                     inpt >> mp_vec[i][j];
  36.                 }
  37.             }
  38.             m_MapVector = mp_vec;
  39.             m_Width = w;
  40.             m_Height = h;
  41.            
  42.             return true;
  43.         }
  44.        
  45.         void Display( )
  46.         {
  47.             for( int i = 0; i < m_Width; i++ )
  48.             {
  49.                 for( int j = 0; j < m_Height; j++ )
  50.                 {
  51.                     std::cout << m_MapVector[i][j];
  52.                 }
  53.                 std::cout << "\n";
  54.             }
  55.         }
  56.        
  57.     private:
  58.         std::vector< std::vector<int> > m_MapVector;
  59.         int m_Width;
  60.         int m_Height;
  61.     };
  62.    
  63.     Map map;
  64.     map.Load( "map.txt" );
  65.     map.Display( );
  66.    
  67.    
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement