Displaying External File Contents C++
Go to solution
Solved by Mr_KoKa,
#include <iostream> #include <fstream> #include <sstream> std::string readFile(std::string s){ std::stringstream ss; std::ifstream inputFile(s.c_str()); if(inputFile.good()){ ss << inputFile.rdbuf(); } return ss.str(); } int main () { std::string fileContents = readFile("test.cpp"); std::cout << fileContents << std::endl; return 0; }

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now