D
Dave
Hello all,
The scheme shown below to move a text file's contents into a std::string
works with one exception: it drops the carriage return and line feed
characters. How may I, in a Standard-compliant way, read in a text file's
contents and keep the carriage returns and line feeds?
Thanks,
Dave
#include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
using namespace std;
//
****************************************************************************
*
//
****************************************************************************
*
//
****************************************************************************
*
int main()
{
string file_contents;
ifstream file_stream("test_1.txt");
copy(
istream_iterator<char>(file_stream),
istream_iterator<char>(),
back_inserter(file_contents)
);
cout << file_contents << endl;
} // main
The scheme shown below to move a text file's contents into a std::string
works with one exception: it drops the carriage return and line feed
characters. How may I, in a Standard-compliant way, read in a text file's
contents and keep the carriage returns and line feeds?
Thanks,
Dave
#include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
using namespace std;
//
****************************************************************************
*
//
****************************************************************************
*
//
****************************************************************************
*
int main()
{
string file_contents;
ifstream file_stream("test_1.txt");
copy(
istream_iterator<char>(file_stream),
istream_iterator<char>(),
back_inserter(file_contents)
);
cout << file_contents << endl;
} // main