I have made a Class called FileReader. This is in my read function of this class. It opens a file and reads it. Of course it puts the content of the file in a variable called "content" of my class. It's at the last line.
std::string file_content;
std::string temp;
std::ifstream file;
file.open(filepath,std::ios_base::in);
while(!file.eof()){
temp.clear();
getline(file, temp);
file_content += temp;
file_content += '\n';
}
file_content = file_content.substr(0, file_content.length()-1); //Removes the last new line
file.close();
content = file_content;
The file I am opening has the following content :
"Hello\nWhat's up\nCool".
Of course I didn't write exactly \n in my textfile. But as you can see there is no new line at the end.
My problem is, "content" has, whenever I print it to the screen, a new line at the end. But I removed the last new line... What's wrong?