How do I read a file into an array?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Emily M
    New Member
    • Oct 2010
    • 1

    How do I read a file into an array?

    As part of an assignment I'm supposed to declare an array and read numbers from a file but I'm stumped. I have no idea on how to do this! the file is called numbers.txt

    please help :)

    this is what I have so far

    Code:
    #include <iostream>
    #include <cstdlib>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    // Function prototypes (ensure you add the comments)
    
    int main()
    {
        ifstream input;
    
        input.open("numbers.txt");
        if (input.fail())
        {
            cout<<"Input file opening failed.\n";
            exit(1);
        }
    
    
        return 0;
    
        input.close();
    }
Working...