Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- int main()
- {
- class Map
- {
- public:
- Map()
- {
- }
- bool Load( const std::string& flnm )
- {
- std::ifstream inpt;
- inpt.open( flnm.c_str( ) );
- if( !inpt.is_open( ) )
- {
- return false;
- }
- int w = 0, h = 0;
- inpt >> w >> h;
- std::vector< std::vector<int> > mp_vec (w, std::vector<int>( h ));
- for( int i = 0; i < w; i++ )
- {
- for( int j = 0; j < h; j++ )
- {
- inpt >> mp_vec[i][j];
- }
- }
- m_MapVector = mp_vec;
- m_Width = w;
- m_Height = h;
- return true;
- }
- void Display( )
- {
- for( int i = 0; i < m_Width; i++ )
- {
- for( int j = 0; j < m_Height; j++ )
- {
- std::cout << m_MapVector[i][j];
- }
- std::cout << "\n";
- }
- }
- private:
- std::vector< std::vector<int> > m_MapVector;
- int m_Width;
- int m_Height;
- };
- Map map;
- map.Load( "map.txt" );
- map.Display( );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement