MSVC++"实用程序"标头中make_pair的定义是:
template<class _Ty1,
class _Ty2> inline
pair<_Ty1, _Ty2> make_pair(_Ty1 _Val1, _Ty2 _Val2)
{ // return pair composed from arguments
return (pair<_Ty1, _Ty2>(_Val1, _Val2));
}
我一直使用make_pair,但不将参数类型放在尖括号中:
map<string,int> theMap ;
theMap.insert( make_pair( "string", 5 ) ) ;
我不应该告诉make_pair第一个论点是std::string不是char*?
怎么知道的?
多图可以包含在其中吗?IE,而不是被定义multimap<char,int>为例如,它将被定义为multimap<pair, pair>?
然后如何对这个多重图进行排序?另外,如何访问每对中的各个内容?
我有这个map<string, vector <pair<int, int> > >变量,并且正在推回一个值,但是code :: blocks告诉我该对没有名为push_back的成员函数。我应该怎么做才能使它推回而不是pair<>.push_back()?
这基本上是我在做什么:
map<string, vector <pair<int, int> > > T;
for(int x = 0; x < data.size(); x++)
T[data[x].str].push_back(data[x].PAIR)
Run Code Online (Sandbox Code Playgroud)
错误是:
error: no matching function for call to 'std::vector<std::pair<int, int>,
std::allocator<std::pair<int, int> > >::push_back(std::map<int, int,
std::less<int>, std::allocator<std::pair<const int, int> > >&)'
Run Code Online (Sandbox Code Playgroud) 这就是我的目标......
vector < pair<vector<int>,int> > var_name (x, pair <vector<int>(y),int>);
Run Code Online (Sandbox Code Playgroud)
其中x是向量var_name的大小,y是对中向量的大小.
上述语句不起作用,因为pair模板只允许常量.我怎样才能将我的向量分别设置为x和y?
我已经定义了一对数组,如下所示:
std::pair<int,int> delta[4];
delta[0] = std::make_pair(0,1);
delta[1] = std::make_pair(1,1);
delta[2] = std::make_pair(1,0);
delta[3] = std::make_pair(1,-1);
Run Code Online (Sandbox Code Playgroud)
但是当我尝试访问以下元素时:
delta[2].first
Run Code Online (Sandbox Code Playgroud)
我收到如下错误:
binary '[' : 'std::pair<_Ty1,_Ty2>' does not define this operator or a conversion to a type acceptable to the predefined operator
error C2228: left of '.first' must have class/struct/union
Run Code Online (Sandbox Code Playgroud)
这是我访问它的功能:
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
int who_won(std::pair<int,int> &delta,std::vector<std::vector<int>> &grid);
int main(int argc, char** argv)
{
std::fstream input;
input.open("E:\\in.txt",std::ios_base::in);
std::string line;
char ch;
std::vector<std::vector<int>> grid;
std::vector<int> row; …Run Code Online (Sandbox Code Playgroud) 这可能吗?
#include <map>
class Example {
private:
std::map<std::string, std::string, less<std::string>,
std::allocator< CustomPair<std::string, std::string> > > myMap;
};
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,CustomPair将是一个包含键和值的模板类.如果这是可能的,那么这么简单还是有什么我应该注意的?
我只是想知道创建数据结构是否是个好主意
std::map< std::pair<int,int>,std::string >
Run Code Online (Sandbox Code Playgroud)
只是想知道如何在内部订购这对......:S
谢谢!
我有一张地图,其值为std :: pair。
尝试设置迭代器时,编译器抱怨如下,但我不明白为什么:
src / DBConnector.cpp:在成员函数'int DBConnector :: createGenericInsert(std :: string,std :: map <std :: basic_string <char,std :: char_traits <char>,std :: allocator <char>>, std :: pair <int,std :: basic_string <char,std :: char_traits <char>,std :: allocator <char>>>,std :: less <std :: basic_string <char,std :: char_traits <char >,std :: allocator <char>>>,std :: allocator <std :: pair <const std :: basic_string <char,std :: char_traits <char>,std :: allocator <char>>,std :: pair <int,std :: basic_string <char,std :: char_traits <char>,std :: allocator <char>>>>>,std :: string&)':src …
现在问题非常困难.现在这是我的主要清单
List<List<KeyValuePair<string, double>>> dblWordFreqByCluster = new List<List<KeyValuePair<string, double>>>();
Run Code Online (Sandbox Code Playgroud)
所以让我们给出示例列表
(house,40),(home,20),(monitor,40)
(home,10),(work,60),(monitor,30)
(school,70),(home,10),(word,20)
Run Code Online (Sandbox Code Playgroud)
所以每一行都是a,List<KeyValuePair<string, double>>并且有一个包含所有这些行的最大列表.
我想要做的是选择每个单词的值,它们的总和,然后在整个列表中划分单词计数.因此,在此修改后,列表将成为以下内容
(house,40),(home,40/3),(monitor,70/2)
(home,40/3),(work,60),(monitor,70/2)
(school,70),(home,40/3),(word,20)
Run Code Online (Sandbox Code Playgroud)
这意味着获取每个键的平均值并更新每个键值.
C#4.0 WPF
我在Visual Studio上遇到了flycapture SDK(FlyCapture v2.6 Rel 2)的问题.这用于BlackFly相机.
我收到以下错误:
Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall FlyCapture2::Error::Error(void)" (__imp_??0Error@FlyCapture2@@QAE@XZ) referenced in function _wmain C:\Users\dahl2\Documents\Visual Studio 2012\Projects\BlackFlyMultiTrigger\BlackFlyMultiTrigger\BlackFlyMultiTrigger.obj BlackFlyMultiTrigger
Error 2 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall FlyCapture2::Error::Error(class FlyCapture2::Error const &)" (__imp_??0Error@FlyCapture2@@QAE@ABV01@@Z) referenced in function _wmain C:\Users\dahl2\Documents\Visual Studio 2012\Projects\BlackFlyMultiTrigger\BlackFlyMultiTrigger\BlackFlyMultiTrigger.obj BlackFlyMultiTrigger
Error 3 error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall FlyCapture2::Error::~Error(void)" (__imp_??1Error@FlyCapture2@@UAE@XZ) referenced in function "void __cdecl PrintError(class FlyCapture2::Error)" (?PrintError@@YAXVError@FlyCapture2@@@Z) C:\Users\dahl2\Documents\Visual Studio 2012\Projects\BlackFlyMultiTrigger\BlackFlyMultiTrigger\BlackFlyMultiTrigger.obj BlackFlyMultiTrigger
Error 4 error LNK2019: unresolved …Run Code Online (Sandbox Code Playgroud)