I was writing a program that opens a file assigns each element to an array. I was wondering if anyone had suggestions on how to get the number of items in a file, without knowing before hand.
I was usuing this:
int main()
{
ifstream inputFile;
inputFile.open("P6.txt");
int index = 0;
int x;
while(inputFile >> x)
{
index++;
}
cout << index;
return 0;
}
I made a dummy file to read crap into, then counted as they were cycled though, this way I can use the index to creat the array and assign elements to it. This seems wonky and I was hoping for some suggestions on how to tackle something like this.