I have a function that reads from a text file and the outputs the whole text file. It looks like this;
string FileInteraction :: read() const
{
ifstream file;
string output;
string fileName;
string line;
string empty = "";
fileName = getFilename();
file.open(fileName.c_str());
if(file.good())
{
while(!file.eof())
{
getline(file, line);
output = output + line ;
}
file.close();
return output;
}
else
return empty;
};
I call the function like this;
cout << FI.read(); //PS I cant change the way it's called so I can't simply put an endl here
if I use return output + "\n"
i get this as output
-- Write + Read --
This is the first line. It should disappear by the end of the program.
-- Write + Read --
This is another line. It should remain after the append call.
This call has two lines.
I don't want that space to between the lines to be there.
So after the function has been called I need to end the line. How can I do that within the function?
PS. Also if there is a better way to output everything in a text file than the way I have done it i would appreciate any suggestions.
Simply change
to