I've been having a hard time for quite a while now trying to read files. These files include English text, pictures music and so on. After hurting in the jungles of Africa or the internet I found something that worked.string str((istreambuf_iterator<char>(fileIn)), istreambuf_iterator<char>());
This made it possible to do all kinds of awesome things. However it did come at the cost of ram the function sucks ram right up until the program closes. What I want to know is how can you make str just give up its ram. Or in a more simplistic explanation not use ram when you don't need it. So if anyone has ideas or criticisms then any help would be awesome.
If you still find the monolog or story above confusing or not worth reading. I simply want to make the str element disappear and not use ram.
// Please just ignore the headers
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <cstddef>
#include <vector>
#include <map>
#include <array>
using namespace std;
int main ()
{
string fileName; // The string for the file name
getline(cin,fileName);// Gets the file name
ifstream fileIn; // ifstream thing
fileIn.open(fileName, ios::in | ios::binary); // Opens the file and sets the mode
string str((istreambuf_iterator<char>(fileIn)), istreambuf_iterator<char>()); // Reads the file and make it usable as a string.
// str also stores the data on ram and pointers don't seem to work to remove it. So it is stuck there untill the program closes.
cout << str << endl;
system("pause");
// This is where I would like it if str was cleared from ram.
str = "NULL"; // Tried to redefine the data here to reduce ram usage. Since pointers seem not to work with the function.
// At this point STR is still on ram and it creates problems
system("pause");
fileIn.close(); // Closes file after reading.
}