input from file into an array

I need to take input from a file and insert it into an array to be used in a later function...

How do I do that?
mainly.. how do i take it character by character

Note: the file is a series of integers separated by space and comma
EX: 1, 2, 48, 23, 76, ...
You could read from the file like this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
    // declare and open the input file
    ifstream fin("filename.txt");

    int num;

    // Loop while a number can be read 
    while (fin >> num)
    {
        // do something with each number
        cout << num << '\n';

        char comma;     // read and ignore 
        fin >> comma;   // the comma separator
    }


http://www.cplusplus.com/doc/tutorial/arrays/
http://www.cplusplus.com/doc/tutorial/files/

Topic archived. No new replies allowed.