pulling numbers from files....

This is a discussion on pulling numbers from files.... within the C++ Programming forums, part of the General Programming Boards category; lol.... ran into a problem.... don't think the actual code is needed for this.... got some string arrays that hold ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    13

    pulling numbers from files....

    lol.... ran into a problem.... don't think the actual code is needed for this.... got some string arrays that hold numbers.... tried dividing those numbers by an int variable.... won't do it.... makes sense.... changed the string arrays to int arrays, getline() won't pull the numbers from the files and put them into an int array.... is there another command/function/whatever it's called that'll do this so I can divide these numbers?

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,643
    something like:

    Code:
     int main(void) {
      int val;
      vector <int> array;
      ifstream in(filename);
      if(in) {
       while(in >> val) {
        array.push_back(val);
        }
       int i, size = array.size();
       for(i = 0; i < size; ++i) {
        cout << "array[" << i << "] = " << array[i] << endl; 
        }
       }
      return 0;
     }
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    13
    lol, this isn't the actual code that I have, but still.... it'll work....
    Code:
    string array[x];
    int number = 0;
    int y = 0;
    void main()
    {
      getline(infile, array[x])
      number = array[x]/((y+1)*3)
    }
    assume that the file's already open and everything and the getline and number lines are inside a loop.... there's alot more to it than that, but everything shown is where my problem is.... getline() won't work with a int array.... changed it to infile >> array[x], it seems to work fine, but I'm sure there's another way....

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,643
    >> getline() won't work with a int array

    no kidding? perhaps you should read your stl documentation at some point?

    >> number = array[x]/((y+1)*3)

    what in god's name are you trying to do there?
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error opening files in a different dir
    By Ozzie in forum C++ Programming
    Replies: 3
    Last Post: 10-09-2008, 06:55 AM
  2. Working with muliple source files
    By Swarvy in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2008, 08:36 AM
  3. Program Deployment and DLL/OCX Files?
    By dfghjk in forum C++ Programming
    Replies: 5
    Last Post: 06-16-2008, 02:47 AM
  4. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  5. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM

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