Thread: apvector...Arrays

  1. #1
    *this
    Join Date
    Mar 2005
    Posts
    498

    apvector...Arrays

    Hi my name is Josh, I am new to the forums. I have been coding for maybe a year or two on and off with different languages, but have settled for c++. I have been working some assignments given to me by a friend, and I was wondering if someone could help me out. In the assignments, the header file apvector.h is used for all arrays. If anyone here is familiar with this header file, could you possibly show me how to do similar functions, but with a more universal header file, like iostream, or a vector header...how would I go about declaring a array, length, resizing, and using it in a function decleration.

    Thanks,
    Josh
    Last edited by JoshR; 03-25-2005 at 10:50 PM. Reason: spelling

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    There is a standard vector header.
    Code:
    #include <vector>
    
    int main()
    {
      std::vector<int> myInt;
      myInt.push_back(10); //add ten to the end of the vector
      return 0;
    }
    As far as declaring an array they just look like this
    Code:
    int main()
    {
      int myArray[10]; //makes an array of 10 ints
      return 0;
    }
    Arrays cannot be resized after declaring their size you can use memory allocation with pointers though works just like an array.
    Code:
    int main()
    {
      int *myPointer;
      myPointer = new array[10]; //this can change it's not stuck at 10
      delete [] myPointer;  //make sure you clean up after memory allocation
      return 0;
    }
    Woop?

  3. #3
    *this
    Join Date
    Mar 2005
    Posts
    498
    Thanks a lot!

Popular pages Recent additions subscribe to a feed