-
0 votesanswersviews
使用包含没有复制运算符的类的std :: map的问题(Gdiplus :: Image)
看来我试图用不可复制的对象填充std :: map,但我还没有实现 . General problem 我想使用std :: map来存储一些名为Image的类型的对象(更准确地说,它是Gdiplus :: Image) . 我写不出这样的话: map<string, Gdiplus::Image> loadedImages ; Gdiplus::Image newImage( CSt... -
2 votesanswersviews
std :: map中的C 11类作为私有构造函数的值
这是类的简化版本,它作为值存储在一个在VS2008中正常工作的 Map 中(注意 all 成员是私有的): class Value{ friend class FriendClass; friend class std::map<std::string, Value>; friend struct std::pair<const std::string, ... -
0 votesanswersviews
如何使用以下模板为 Map 声明迭代器 - std :: map <std :: string,T> my_map?
我有以下课程声明 - template <typename T> class Polynomial{ std::map<std::string, T> _polynomial_ } 在一个成员函数中,我为此声明了一个迭代器 - typename std::map<std::string, T>::iterator it= _polynomial_.beg... -
1 votesanswersviews
无法将元素添加到std :: map
Foo.h: class Foo { public: Foo(void); ~Foo(void); void AddScreen(std::string name, ScreenBase &screenToAdd); private: std::map<std::string, ScreenBase> m_screens; }; F... -
0 votesanswersviews
将std :: set或std :: map与共享内存一起使用
我正在一个有两个不同过程的项目中工作 . 第一个进程是std :: map或std :: set上的缓存,它分配共享内存区域中的所有数据 . 第二个进程是一个 生产环境 者/消费者,它可以访问共享内存,所以每当它需要一些数据时,它会通过一个unix管道向缓存进程询问包含所请求数据的共享内存的起始地址 . 到目前为止,我提出了两种方法,首先是将std :: set的分配函数更改为始终在共... -
-1 votesanswersviews
如何破坏 Map 并在C中填充 Map 指针?
如果我们创建 map<int,int> ,我们可以清除它但它仍然留在内存中,对吗?例如 . #include <map> using namespace std; int main(){ map<int,int> myMap; myMap[1] = 2; myMap.clear(); return 0; } 但是如果我们设置一个指... -
9 votesanswersviews
根据插入时间从std :: map中删除元素
我需要根据插入时间(或其他更高效的东西)从std :: map中删除元素 . Map 可能包含数千个元素,如果我存储时间并迭代 Map 以检查每个元素的时间,它可能最终会非常耗时 . 有没有人知道如何在std :: map老化时擦除它们? -
3 votesanswersviews
std :: map :: rend()返回数组的第一个元素,而不是之前的元素
我正在尝试通过std :: map反向迭代,遵循以下代码:http://www.cplusplus.com/reference/stl/map/rend/它说: rend()返回一个反向迭代器,引用映射容器中第一个元素之前的元素,这被认为是它的反向结束 . 请注意,rend不会引用与begin相同的元素,而是引用它之前的元素 . map<float,int> m; m.insert... -
0 votesanswersviews
带有map和struct的初始化列表
我有一个带字符串键和结构值的映射,我不知道为什么我不能使用a list of initializers实例化一个对象: #include <string> #include <map> using namespace std; struct CodeInfo { int _level = 0; bool _reactive; }; typedef ... -
59 votesanswersviews
如何为 Map 创建自己的比较器?
typedef map<string, string> myMap; 当将新对插入 myMap 时,它将使用键 string 通过其自己的字符串比较器进行比较 . 是否可以覆盖该比较器?例如,我想比较密钥 string 的长度,而不是字母表 . 或者还有其他方法来排序 Map 吗? -
-2 votesanswersviews
在std :: map中插入数据[关闭]
我有以下容器: map<int,string,string> data; 我一直在尝试使用以下代码(一次一个)将信息存储在该 Map 中,但它们都不起作用 . data.insert( m, f, l ); data.insert( map<int,string,string>(m, f, l) ); data.insert( pair<int,string,str... -
185 votesanswersviews
如何从std :: map中检索所有键(或值)并将它们放入向量中?
这是我出来的可能方式之一: struct RetrieveKey { template <typename T> typename T::first_type operator()(T keyValuePair) const { return keyValuePair.first; } }; map<int, int> m;... -
3 votesanswersviews
std :: map中的vector <int> :: iterator与list <int> :: iterator键
为什么可以定义vector :: iterator to int的map,但是list :: iterator to int的map不能? #include <vector> #include <list> #include <map> #include <algorithm> using namespace std; int main() { ... -
0 votesanswersviews
如何填充映射的多图?
我有以下映射的multimap: map<int, multimap<int, pair<string, string>>> modCreAlt; 我想在其中插入一行: int priority = ... ; string alertInv = ... ; string upperAlertInv = ... ; modCreAlt.insert(make... -
5 votesanswersviews
std :: map get value - find vs handcrafted loop [关闭]
我有一个std :: map对象 map<string , Property*> _propertyMap ,其中 string 是属性的名称, Property* 包含属性值 . 我需要处理属性值并将它们转换为特定的数据格式 - 每个属性都有自己的格式,例如..如果映射初始化如下: _propertyMap["id"] = new Property(Prope... -
0 votesanswersviews
std :: map中的重复项
我们的产品中有一段代码,它使用std :: map来存储数据,其关键是boost :: make_tuple(std :: string,std :: string) . 在调试问题时,我发现在映射中插入键值对后,在映射中找到该键导致为负,并且另一次尝试插入键值1对成功 . 这说明了操作顺序: Flow A: Key k = boost::make_tuple(str1, str2); bool... -
0 votesanswersviews
从文本文件中将邻接列表读入映射
我正在编写一个实现Dijkstra算法的程序,并决定使用 Map 对象来保存顶点( Map 键)和连接的顶点与路径距离( Map 值)配对 . 连接的顶点与坐标对之间的距离配对 . 示例文本文件输入如下: 1 2,3 3,2 2 4,4 3 2,1 4,2 5,3 4 5,2 6,1 5 6,2 6 1,9 每行中的第一个数字将作为键读入,其中坐标对将被读入初始化为保持对的向量 . 我尝试使用&... -
0 votesanswersviews
在std :: map中搜索时堆栈溢出
由于某种原因,此代码在运行时导致堆栈溢出异常: neuralnetwork::CPerceptron::inputEvent(const neuralnetwork::IConnection * origin, double value) std::map<std::reference_wrapper<const IConnection>, float64_t, _CPe... -
0 votesanswersviews
使用boost :: shared_ptr编译std :: map时出错
我想在vs2005中编译我的代码 . 我正在使用std :: map和boost :: shared_ptr(v1.47.0)我的代码看起来像这样 struct B { int a; } typedef boost::shared_ptr<B> K; std::map<const std::string, K > mymap; //some code std:... -
370 votesanswersviews
在C中初始化静态std :: map <int,int>
初始化静态 Map 的正确方法是什么?我们需要一个初始化它的静态函数吗? -
0 votesanswersviews
std :: map引用键时的行为
我正在编写一个数值模拟程序,使用std :: map来存储一些键值对 . 该图用于存储模拟期间演变的状态 . 密钥的类型是一个整数,对应于密钥的值表示相同密钥的副本数量,即std :: map . 对于模拟的每个步骤,我需要计算同一个键有多少个值,所以我将通过以下代码检查 if (map[key]>0) {do something here with the number of copies... -
0 votesanswersviews
如何使用std :: map从模板中获取数据类型
我需要一个代码,需要使用std :: map并创建一个数据类型列表及其大小 . 例如 "BYTE" 表示 'unsigned char' , "BOOL" 表示 'bool' , "INT" 表示 'unsigned int' 等 . 我需要从用户那里获取的输入是字符串(数据类型名称),我需要创建列表 . 一旦用户请求特定数据类型的指针,... -
-3 votesanswersviews
带有std :: pair的映射中的C count函数
我正在尝试编写一个函数,它有一个unsigned int作为输出,两个无符号整数作为输入 . 现在由于这个函数已经递归定义,我试图使用std :: map实现memoization以提高时间效率 . 码: unsigned memo_ack(unsigned m,unsigned n) { static map <pair<int,int>,unsigned> ... -
30 votesanswersviews
检查值存在于std :: map - C中
我知道find方法在std :: map中找到提供的键,并将迭代器返回给元素 . 反正有没有找到值并获得元素的迭代器?我需要做的是检查std :: map中是否存在指定的值 . 我通过循环 Map 中的所有项目并进行比较来完成此操作 . 但我想知道有没有更好的方法 . 这是我写的 bool ContainsValue(Type_ value) { bool found = false; ... -
3 votesanswersviews
避免在没有原始指针的情况下复制 Map 的密钥
每次在std :: map中插入一对,其键是std :: string时,它会生成两个副本 . 您可以避免使用原始指针,但它是异常不安全的 . 有没有办法使用智能指针而不是原始指针? 示例代码: // To compile: g++ -std=c++0x exmaple.cpp -o example #include <iostream> #include <string&g... -
5 votesanswersviews
c value_type不适用于std :: map中的std :: tr1:tuple
以下代码段适用于Visual Studio 2008,但不适用于Visual Studio 2010 . template <typename TKey> struct MyStruct { typedef std::map<TKey, int> Keys; MyStruct() { } void set(TKey& k... -
12 votesanswersviews
map <string,string>如何在此 Map 中插入数据?
我需要以键值格式存储字符串 . 所以我正在使用如下的 Map . #include<map> using namespace std; int main() { map<string, string> m; string s1 = "1"; string v1 = "A"; m.insert(pai...