Getting Input to fill an array

This is a discussion on Getting Input to fill an array within the C++ Programming forums, part of the General Programming Boards category; I don't quite understand how to get an input file to fill an array. It's part of a much bigger ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    2

    Getting Input to fill an array

    I don't quite understand how to get an input file to fill an array. It's part of a much bigger program, and I need this file (filled with 20 numbers) to be read in it's entirety (an eof?) to an array.

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,652
    So what have you tried? Do you know anything about arrays?

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    2
    I understand arrays pretty well. It's combining one with an input file that confuses me.
    Here is what I have so far:
    Code:
    void fill_array(int a[],int size, int& number_used) 
    
    {
         int next,index =0;
         using namespace std;
         ifstream in_stream;
         in_stream.open("SUPERNUMBERS.txt");
         if(in_stream.fail( ))
            {
                cout << "In stream failed.\n";
                exit (1);
            }
         in_stream.get(next);
         while (! in_stream.eof( ))
         {
               a[index] = next;
               index ++;
               cin >> next;
         }
         number_used = index;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fill the array help
    By IMMORTALX in forum C Programming
    Replies: 7
    Last Post: 09-09-2011, 04:34 AM
  2. Replies: 2
    Last Post: 04-27-2008, 04:39 AM
  3. fill array with number
    By nevrax in forum C Programming
    Replies: 9
    Last Post: 03-28-2007, 05:53 PM
  4. how to fill multiple array locations with one input
    By kryonik in forum C++ Programming
    Replies: 5
    Last Post: 06-08-2006, 11:12 PM
  5. Trying to fill an int array
    By boojus in forum C++ Programming
    Replies: 3
    Last Post: 11-21-2003, 02:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21