Advertisement
Guest User

Untitled

a guest
May 27th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. //Creating ifstream and opening file
  2.         std::ifstream file;
  3.         file.open("Load/Level.txt");
  4.  
  5.         //If the file is open...
  6.         if(file.is_open())
  7.         {
  8.                 //Success
  9.                 std::cout << "File Opened successfully!!!. Reading data from file into array" << std::endl;
  10.                 //As long as it's not at the end of the file..
  11.                 while(!file.eof())
  12.                 {
  13.                         //For loop
  14.                         for(int i = 0; i < HEIGHT; i++)
  15.                         {
  16.                                 //Nested for loop..
  17.                                 for(int j = 0; j < WIDTH; j++)
  18.                                 {
  19.                                         //Get the next value from file and store it into level[i][j].
  20.                                         //Do this for WIDTH(100) times for the width, and HEIGHT(25) times for the height.
  21.                                         file >> level[i][j];
  22.                                 }
  23.                                 //If the for loop above can't run anymore, it's the end of the line.
  24.                                 std::cout << std::endl;
  25.                         }
  26.                 }
  27.         }
  28.         else
  29.         {
  30.             //Failed
  31.             std::cout << "File didn't open!" << std::endl;
  32.         }
  33.         //Close the file again.
  34.         file.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement