I have a line file. I want to put each of its lines into an array, but I need to know the exact size of the space occupied by the array. How can I recognize it? Will the following code work:
#include <fstream>
using namespace std;
void main()
{
ifstream* file = new ifstream("file.txt");
string str;
long int count;
long int sizeArray;
while(*file >> str)
{
count++;
sizeArray += sizeof(str) * sizeof(char);
}
file->clear();
file->seekg(0);
string* array = new string[count];
long int place = 0;
while(*file >> str)
{
array[place] = str;
place++;
}
// sizeArray worked?
cout << sizeArray << endl;
}