I am creating int array using c++ and trying to get the length of it
int *masterArray;
int count = 0;
int a = 0;
int var = 0;
ifstream myfile("sample_10.txt");
if (myfile.is_open())
{
while(myfile.good())
{
string word;
while(getline(myfile, word))
{
count++;
}
cout << "count: " << count << endl;
masterArray = new int [count];
myfile.clear();
myfile.seekg(0);
while(getline(myfile, word, '\n'))
{
cout << word << " ";
istringstream ( word ) >> var;
masterArray[a] = var;
a ++;
}
}
}
name of the int array is master array, and after I add variables in the array I do..
cout << "sizeof(masterArray) : " <<sizeof(masterArray);
which gives me 8, instead of 10.
I tried to print out all variables stored in the array and it gives me 10, which means all variables are stored correctly.
should I retrieve the length by doing
cout << "sizeof(masterArray) : " <<sizeof(masterArray) / sizeof(*masterArray);
??
Because that gives me 2 (obviously, cuz it is dividing 8 by 4)
Thanks