Retrieve Values from a List; also, How To Determine Minimum Value from a List

Hello. I have two questions - 1) I need to retreive values from a text document. How do I do that? I am writing the text document myself - so the format is flexible. The purpose of retreiving the values is to determine the minimum value. So the values will be numerical, obviously. And 2) I need to know how to determine the minimum value from a numerical list, such as in the case above. Thank you so much For your help. -- Brian
Reading data from a file is simple:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <fstream>
#include <iostream>
using namespace std;

int main(){
ifstream file; //our file object
int myarray[10]; //to store the values from our file
int c = 0; //a counter

file.open("filename.txt"); //simple enough
while (c<=9){ //go through our array (a for loop would probably be better here
file >> myarray[c]; //extract a value into the array at c (values must be seperated by a space)
c++; //next
}
file.close(); //its a good habit to close files, even if they are local to a function
return 0;}


Ordering would be a bit more tricky. I would use a counter variable, and 2 temp. variables to store the current lowest number and its position. Then I would check each indice of the array at our counter against the temp variable, and if it is lower, make the temp variable equal to it, then store its position in the other temp. When done, I would output the indice at the stored position.
Last edited on
Topic archived. No new replies allowed.