I'm writing a function to load a txt file and return a const char* the function below works, my question is will this function cause a memory leak if I don't store *pS and then call delete pS ?
const char* loadFile(string fname)
{
string line,text;
ifstream in(fname);
while(std::getline(in, line))
{
text += line + "\n";
}
string *pS = new string(text);
const char* data = pS->c_str();
return data;
}
the function is used in my code as follows
static const char* pVS;
...
pVS = loadFile("VS.txt");
...
delete pVS;
Will this delete the string ?