![]() |
| | #1 |
| Registered User Join Date: Aug 2008 Location: Bolivia
Posts: 3
| Adding More Array Elements? PHP Code: |
| Vermillion is offline | |
| | #2 |
| and the hat of sweating Join Date: Aug 2007 Location: Toronto, ON
Posts: 3,271
| Easy... use a std::vector instead of an array.
__________________ "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008 |
| cpjust is offline | |
| | #3 |
| and the Hat of Ass Join Date: Dec 2007
Posts: 809
| Closest thing to a PHP associative array in C++ is the Standard Template Library's map container. However, even that requires an actual key, so cpjust is right; for the example you've provided, an STL vector would probably make more sense: Code: #include <iostream>
#include <vector>
#include <string>
int main()
{
std::vector<std::string> myArray;
myArray.push_back("James");
myArray.push_back("Andy");
myArray.push_back("Nick");
for (unsigned int i = 0; i < myArray.size(); ++i)
{
std::cout << "Element " << i << ": " << myArray[i] << std::endl;
}
return 0;
}
|
| rags_to_riches is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| adding elements in array | reb221 | C Programming | 6 | 12-30-2008 02:41 PM |
| Setting all elements of an array to zero | kolistivra | C Programming | 9 | 08-29-2006 02:42 PM |
| Type and nontype parameters w/overloading | Mr_LJ | C++ Programming | 3 | 01-02-2004 01:01 AM |
| Merge sort please | vasanth | C Programming | 2 | 11-09-2003 12:09 PM |
| Help with an Array | omalleys | C Programming | 1 | 07-01-2002 08:31 AM |