Thursday, July 9, 2009

Where is the best C++ Array class out there? Looking for something with many features (sort) and is fast.?

Im looking for a fast and efficient C++ Library or class to provide arrays with features like those found in ruby. Things like add to end, sort, etc. Where can I find something like this thanks in advance.

Where is the best C++ Array class out there? Looking for something with many features (sort) and is fast.?
Did you try std::vector yet?





Keep in mind that C++ and ruby are different languages with very different philosophies. If you are looking to recreate Ruby in C++ you are likely going to be disappointed. That said, you can accomplish all the same things the C++ Way.





Here is simple example of how to use vector and the std::sort:





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;vector%26gt;


#include %26lt;algorithm%26gt;





using namespace std;





int main(int argc, char *argv[])


{


vector%26lt;string%26gt; myArray;





string s1("Hello World");


string s2("No do-overs in life");


string s3("GoodBye Cruel World");








myArray.push_back(s1);


myArray.push_back(s2);


myArray.push_back(s3);





sort(myArray.begin(), myArray.end());





for (int i = 0; i %26lt; myArray.size(); ++i)


{


cout %26lt;%26lt; myArray[i] %26lt;%26lt; endl;


}


}

buy flowers

No comments:

Post a Comment