reading from a txt file

how do you write something that has a separate text file and the program must read the numbers in the file and compute each number given a formula??

i know that you have to load data using
ifstream indata ("numbers.txt")

but i dont know how the program knows to read the numbers and computes the numbers in the equation such as the mean of all numbers.
i dont know where to start after this, please help!

Just like with std::cin, to read a number from a file, indata >> my_number;. If there are many numbers and you want to do things with them, put this in a loop. If you don't know how many numbers you'll have, you can put this as a loop condition. When this operation fails, it will evaluate to false.
Topic archived. No new replies allowed.