I need help with a project.

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.
Wow. That is your teachers idea of an easy problem to start off the year with? Yikes.

Best idea would be to load the file, then getline its entirety and parse for ints? gl.
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
}

https://www.startpage.com/do/dsearch?query=reading+numbers+from+a+text+file+c%2B%2B&cat=web&pl=ext-ff&language=english

I also would recommend that you get a good book about C++ like
The C++ Programming Language 4th ed by Bjarne Stroustrup
Topic archived. No new replies allowed.