copy txt file to string c++ code example
Example: c++ read text file to string
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream ifs("myfile.txt");
//Two ways:
//Assign it at initialization
string content( (istreambuf_iterator<char>(ifs) ),
(istreambuf_iterator<char>() ) );
//Assign it after initialization
content.assign( (istreambuf_iterator<char>(ifs) ),
(istreambuf_iterator<char>() ) );
return 0;
}