I'm currently taking an intro to computer science course in college and I'm having a lot of trouble thanks to having a horrendous teacher who teaches in the most confusing way imaginable. We currently have to do this problem:
Write a program that reads signed int values from a file. The program does stop when there is no more data to be read from the file.
Using a single while loop, calculate the maximum value and the minimum value of all the int values read from the file and display the results such as
The maximum value of all the numbers in the file <filename> (string) is <value> (signed int).
The minimum value of all the numbers in the file <filename> (string) is <value> (signed int).
He told me to write a txt file to refer to in the project folder, which I did write ten numbers, but I have no clue what to do afterwards. I don't know how to make a while loop out of it or how to open the file. Nothing on the internet is helping and I'm fearing I'm never going to understand it.
You basically read from a (text)file like you read from std::cin using the >> operator.
So first you create an ifstream called input, check that it is open and then you read all the numbers like this:
1 2 3 4 5
int num;
while (input >> num)
{
// do sth. with num
}