Closed Thread
Results 1 to 3 of 3

Thread: Help with Arrays and Vectors!!!

  1. #1
    PrettyVacant is offline Newbie
    Join Date
    Oct 2007
    Posts
    3
    Rep Power
    0

    Help with Arrays and Vectors!!!

    Hi, I am new to C++ and I am gettting confused with arrays and vectors. What exactly is the difference?
    I want to create an array/vector of strings, with 8 rows and 8 columns, and then to insert strings into the array in a for loop, but I have no idea how to add to an array once it is created, please help!

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    v0id is offline Retired
    Join Date
    Apr 2007
    Posts
    2,937
    Blog Entries
    3
    Rep Power
    42
    A vector is a C++-feature which handles the memory for you, like resizing the space for objects, etc. Arrays doesn't have these features, so you've to handle the memory yourself; resizing, allocation, etc. If you know a fixed size, like 8 x 8, then you can easily use an array,

    This is a simple example, using arrays.
    Code:
    #include <string>
    // ...
    std::string My8x8array[8][8];
    
    My8x8array[0][0] = "0x0";
    My8x8array[0][1] = "0x1";
    // ...
    My8x8array[7][6] = "7x6";
    My8x8array[7][7] = "7x7";
    
    std::cout << My8x8array[0][0] << std::endl;
    std::cout << My8x8array[0][1] << std::endl;
    // ...
    std::cout << My8x8array[7][6] << std::endl;
    std::cout << My8x8array[7][7] << std::endl;

  4. #3
    PrettyVacant is offline Newbie
    Join Date
    Oct 2007
    Posts
    3
    Rep Power
    0
    Great! Thanks a million!

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Vectors
    By vasil_9x in forum C and C++
    Replies: 1
    Last Post: 03-07-2011, 11:18 AM
  2. C++ Vectors
    By Hunter100 in forum C and C++
    Replies: 8
    Last Post: 06-27-2010, 09:50 PM
  3. Flash: Arrays and Vectors
    By chili5 in forum Tutorials
    Replies: 2
    Last Post: 09-08-2009, 09:09 AM
  4. Vectors
    By chili5 in forum Java Tutorials
    Replies: 10
    Last Post: 02-17-2009, 04:55 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts