Skip to content

Instantly share code, notes, and snippets.

@yoggy
Created October 2, 2017 04:48
Show Gist options
  • Save yoggy/5dfe6e9569b4edbc9df2abfb6e455478 to your computer and use it in GitHub Desktop.
Save yoggy/5dfe6e9569b4edbc9df2abfb6e455478 to your computer and use it in GitHub Desktop.
//
// file2string.cpp
//
// see also... https://stackoverflow.com/questions/2602013/read-whole-ascii-file-into-c-stdstring
//
#include <fstream>
#include <sstream>
#include <iostream>
int main(int argc, char *argv[])
{
std::ifstream ifs("test.txt");
if (!ifs) {
std::cerr << "cannot open file..." << std::endl;
return -1;
}
std::stringstream ss;
ss << ifs.rdbuf();
std::cout << ss.str() << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment