It prints 4x abc123.
In file.txt is 3x abc123 writed. In line 17, it prints 3x abc123, this must be, while in line 29 it only prints abc123 1 time. How can I edit this?
// read all the lines in a text file into one string with newlines stripped
std::string readfile_1( const std::string& in_file_name )
{
std::ifstream file(in_file_name) ;
std::string result ;
std::string line ;
while( std::getline( file, line ) ) result += line ;
return result ;
}
// read contents of text file into a string
std::string readfile_2( const std::string& in_file_name )
{
std::ifstream file(in_file_name) ;
return std::string( std::istreambuf_iterator<char>(file),
std::istreambuf_iterator<char>() ) ;
}