fstream to const char *

c++, fstream

Solution

#include <string>
#include <fstream>

int main()
{
   std::string line,text;
   std::ifstream in("test.txt");
   while(std::getline(in, line))
   {
       text += line + "\n";
   }
   const char* data = text.c_str();
}

Be careful not to explicitly call delete on data

Problem

What I want to do is read a file called "test.txt", and then have the contents of the file be a type const char *. How would one do this?

Original source

Related problems