Loop interpretation

  ascii-art, c++, interpretation

I’m having trouble in understanding some part of this code I’ve found online, its goal is to print ASCII art from a .txt file. To be more accurate, I’m having trouble in undesrstanding the while loop in line 28 which is part of the string function "getFileContents". What’s the meaning of ‘TempLine’?

#include <iostream>
#include <fstream>

#include <string>

std::string getFileContents (std::ifstream&);            //Gets file contents

int main(int argc, char *argv[])
{

    std::ifstream Reader ("File1.txt");             //Open file

    std::string Art = getFileContents (Reader);       //Get file
    
    std::cout << Art << std::endl;               //Print it to the screen

    Reader.close ();                           //Close file

    return 0;
}

std::string getFileContents (std::ifstream& File)
{
    std::string Lines = "";        //All lines
    
    if (File)                      //Check if everything is good
    {
    while (File.good ())
    {
        std::string TempLine;                  //Temp line
        std::getline (File , TempLine);        //Get temp line
        TempLine += "n";                      //Add newline character
        
        Lines += TempLine;                     //Add newline
    }
    return Lines;
    }
    else                           //Return error
    {
    return "ERROR File does not exist.";
    }
}

Source: Windows Questions C++

LEAVE A COMMENT