I've been really troubled by this problem. It may sound ridiculous, but this is exactly what happened in my terminal.
int* nums = new int[100];
cout << sizeof(nums);
but the block above outputs 8
instead of 100
; can anyone please help?
Full program (readfile.cpp):
// imports
pair<int, int*> Readfile::readfile (string dirc) {
string fn;
if (dirc.compare("") == 0) {
cout << ">>> Input file name: "; cin >> fn; cout << endl;
}
else
fn = dirc;
ifstream infile(fn);
string line;
vector<int> ints;
while (getline(infile, line)) {
istringstream iss(line);
for (string k; iss >> k; )
ints.push_back(stoi(k));
}
int* nums = new int[100];
cout << sizeof(nums);
copy(ints.begin(), ints.end(), nums);
int n = sizeof(nums)/sizeof(nums[0]);
pair<int, int*> pii(n, nums);
return pii;
}
int main() {
Readfile rdf;
rdf.readfile("..\\insertion\\temp.txt"); // a text file consisting of 100 random integers separated by spaces
return 0;
}
Any help is greatly appreciated.