I wrote a C++ program to remove negatives from a huge list of numbers for which I only want the positives, but I'm having trouble getting the data from my file into the array. Here's the specific part of the code I can't get to work:
int i = 0;
double list1[7925];//initial list of numbers
double list2[7925];//numbers without negatives or zero
std::fstream list1file;
list1file.open("3.1 b data file 2.txt", std::ios::out);
while (i < 7925)//There are 7925 numbers in the list
{
list1file >> list1[i];//read data from file into list1 array
i++;
}
//code to remove negatives from list and copy new list to another array
i = 0;
while (i <7925) {
std::cout << list1[i] <<"\n";//output list of only positive numbers /*the actual program has "list2[i]" here but I changed it for the purpose of testing whether the data was being copied from the file to list1array*/
i++;
}
For whatever reason it spits a bunch of copies the number -9.25596e+61, which I don't think is even a number in the data file. I've been Googling for hours and I can't figure out how to fix this. Am I using the ">>" operator wrong? If so, what do I do instead?