I am writing an embedded app. In some places, I use std::ostringstream a lot, since it is very convenient for my purposes. However, I just discovered that the performance hit is extreme since adding data to the stream results in a lot of calls to malloc and free. Is there any way to avoid it?
My first thought was making the ostringstrea...
I need an STL-like bidirectional iterator (operator<, begin(), rbegin(), end(), rend()) as an inner class to the following (I already spent considerable time all by myself to put together a working tree from a C# article in J of Object Tech and translated it to C++):
template<typename K, typename V> class rbtree {
public:
rbtree()...
I want to create a list of queues in C++ but the compiler gives me some cryptic messages:
#include <list>
#include <queue>
class Test
{
[...]
list<queue> list_queue;
[...]
}
Output:
error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int...
The code fail at compilation line
map_free_segments [ loc ] = color;
The first line for the errors is :
error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const localization'
The complete source : ...
I've made countless attempts to get this working, but everything I do gives me run-time errors. I've been trying to make asset managers to manage content for my game engine, and I'm using lua and luabind for my scripting. Getting everything to compile, binding classes and variables, and getting basic variables back from lua have been no ...
Why does the following not work:
#include <iostream>
#include <fstream>
#include <stack>
std::stack<std::ifstream> s;
-PT
...
I need to keep track of std::set element by saving the iterator returned by set.find().
My questions is does insertion and removing other elements invalidates the obtained iterator? From a simple test I did I can see it is not, but I'd like to ensure this feature is by design.
...
Hey all -
I'm writing a multi-threaded demo program using pthreads, where one thread loads data into an STL queue, and another thread reads from it. Sounds trivial, right? Unfortunately, data pushed into the queue is vanishing. I'm not new to multithreading, nor am I unfamiliar with memory structures - however, this has me stumped.
...
std::find_if takes a predicate in one of it's overloaded function. Binders make it possible to write EqualityComparators for user-defined types and use them either for dynamic comparison or static comparison.
In contrast the binary search functions of the standard library take a comparator and a const T& to the value that should be used...
Why can't I do this:
struct sName {
vector<int> x;
};
It takes only three pointers to store a vector, so I should be able to do this?
...
I have a Visual Studio 2005 solution with several projects that build independently of each other. The main project statically links the other projects. I'm getting very strange STL vector corruption in one of those statically-linked libraries. For example, I declare a std::vector and then perform a sort( thatVector.begin(), thatVector.e...
I've written a custom hashing for my custom key in stdext::hash_map and would like to check whether the hasher is good. I'm using STL supplied with VS 2008. A typical check, as I know, is to check the uniformity of distribution among buckets.
How should I organize such a check correctly? A solution that comes to my mind is to modify ST...
HI! Anyone know how I can make the line "chug(derlist);" in the code below work?
#include <iostream>
#include <list>
using namespace std;
class Base
{
public:
virtual void chug() { cout << "Base chug\n"; }
};
class Derived : public Base
{
public:
virtual void chug() { cout << "Derived chug\n"; }
void foo() { cout << "Der...
i have a std::map and i am using iterator to find a certain key,value pair. After finding it i am unable to get the position of the key,value pair from the iterator. By doing another find i can get it, but i want a work around for this.
//mycode is this
std::map<std::string,myclass*> mymap;
size_t myfind(const std::string &s)
{
std::...
Hi,
I've got wide string and I'm writing it to a wofstream that I opened in out|binary mode. When I look in the resultant file, it's missing every other byte.
I was expecting that when I opened the file in visual studio with the binary editor that I'd see every other byte as a zero, but I'm not seeing the zeros.
Do you know what I'm m...
I have a case where I wish to store a list of resources in a std::vector. As I see it, my options are as follows:
Give my resource a default constructor
Store them as heap objects (and wrap them in a shared pointer)
Option 1 makes it possible to construct invalid resources and option 2 forces me to use the heap.
Am I missing any opt...
In C++/STL sorting is done by using only the less-than operator. Altough I have no idea how the sorting algorithms are actually implemented, I assume that the other operations are created implicite:
a > b *equals* b < a == true
a == b *equals* !(a < b) && !(b < a)
Compared to using a trivalue* compare function, like for example Java, ...
This code works:
class Test
{
public:
Test(string name) : _name(name) {};
bool operator()() { cout << "hello " << _name << endl; return true; }
string name() { return _name; }
private:
string _name;
};
pair<string, bool>
inline execute_test(Test* t) {
return pair<string, bool>(t->name(), (*t)());
}
int main()
{
vector<Test...
When I first started to program in C# last year, I immediately looked for the equivalent to STL's map, and learned about Dictionary.
UPDATE crossed out this garbage below, I was completely wrong. My experience with STL's map was that I hated when I requested it for a value, and if the key wasn't in the map, it would automatically creat...
I need to have a map like this :
typedef std::map<int, float , char> Maptype ;
What is the syntax to insert and searching elements of pair in this map.
...