By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,808 Members | 1,481 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,808 IT Pros & Developers. It's quick & easy.

How do I read a file into an array?

P: 1
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

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <fstream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. // Function prototypes (ensure you add the comments)
  9.  
  10. int main()
  11. {
  12.     ifstream input;
  13.  
  14.     input.open("numbers.txt");
  15.     if (input.fail())
  16.     {
  17.         cout<<"Input file opening failed.\n";
  18.         exit(1);
  19.     }
  20.  
  21.  
  22.     return 0;
  23.  
  24.     input.close();
  25. }
  26.  
Oct 21 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.