I was trying to write a templatized quicksort function. The thought in my head was that I would write a quicksort that can operate on any data structure that has a subscript operator and an order relation on the objects contained within it, so I could do things like
quicksort<deque<int> >();
quicksort<vector<string> >();
etc.
I star...
Check the following code:
string toLowerCase(const string& str) {
string res(str);
int i;
for (i = 0; i < (int) res.size(); i++)
res[i] = (char) tolower(res[i]);
return res;
}
class LeagueComparator
{
public:
bool operator()(const string& s1, const string& s2)
{
return toLowerCase(s1) < toLower...
Let's say I have a bunch of Donut objects, and each of these donuts has a public integer attribute diameter. If I have a vector of donuts, how can I extract the donut with the smallest or largest diameter?
...
Hello,
I keep seeing reference to both the C++ standard Library and the C++ Standard Template Library (STL). What is the difference between them? Wiki mentions that they share some headers but that's about it.
Thanks
...
Hi there, guys!
I'm implementing a custom container with an STL-like interface for a 3D grid control for my scientific software. This is my second question regarding the iterator class for this container. Thanks for helping me with the first!
My question is just like "How do you avoid code duplication when implementing const and non-co...
Is there anyway I can transfer data from an fstream (a file) to a stringstream (a stream in the memory)?
Currently, I'm using a buffer, but this requires double the memory, because you need to copy the data to a buffer, then copy the buffer to the stringstream, and until you delete the buffer, the data is duplicated in the memory.
std:...
I have
typedef std::queue<MyObject*> InputQueue;
std::vector<InputQueue> inp_queue;
Now what I want to do is define at runtime say 5 queues and place data on those queues like
inp_queue[1].push(new MyObject());
etc.
I got it to compile, but it core dumps right away. I guess I need to actually add the queues to the vector first (...