C++ aixc++;地图编辑问题
我无法在AIX中编译以下代码,而Linux和Solaris在这方面似乎还可以。它给了我对C++地图使用和密钥对的WRT问题。C++ aixc++;地图编辑问题,c++,aix,stdmap,std-pair,xlc,C++,Aix,Stdmap,Std Pair,Xlc,我无法在AIX中编译以下代码,而Linux和Solaris在这方面似乎还可以。它给了我对C++地图使用和密钥对的WRT问题。 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> #include <map> #define TRUE 1 #define FALSE 0 using namespace std; std::pa
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <map>
#define TRUE 1
#define FALSE 0
using namespace std;
std::pair<std::string, std::string> mDataMap[] =
{
std::make_pair(std::string("HOME"), std::string("home")),
std::make_pair(std::string("RETURNED"), std::string("Returned"))
};
size_t iSize = sizeof(mDataMap) / sizeof(mDataMap[0]);
std::map<std::string, std::string> mMap2;
const char* getValue(const char *key)
{
std::map<std::string, std::string>::iterator it;
it = mMap2.find(key);
if (it != mMap2.end())
{
return (it->second).c_str();
}
return NULL;
}
int initMap()
{
int retVal = 0;
int i = 0;
for (i = 0; i < iSize; i++)
{
mMap2[std::string(mDataMap[i].first.c_str())] = std::string(mDataMap[i].second.c_str());
}
if (i == iSize)
{
retVal = 1;
}
return retVal;
}
int main()
{
initMap();
std::map<std::string, std::string>::iterator mItr;
// second insert function version (with hint position):
mItr = mMap2.begin();
cout << "\n Map contains \n ";
for (mItr = mMap2.begin(); mItr != mMap2.end(); mItr++)
{
cout << mItr->first.c_str() << " " << mItr->second.c_str() << endl;
}
const char *str = NULL;
str = getValue("HOME");
cout << "getValue(HOME) " << str << endl;
str = getValue("RETURNED");
cout << "getValue(RETURNED) " << str << endl;
return 0;
}
#包括
#包括
#包括
#包括
#包括
#定义真1
#定义FALSE 0
使用名称空间std;
std::pair mDataMap[]=
{
std::make_pair(std::string(“HOME”)、std::string(“HOME”),
std::make_pair(std::string(“返回”)、std::string(“返回”))
};
size_t iSize=sizeof(mDataMap)/sizeof(mDataMap[0]);
std::map mMap2;
常量字符*获取值(常量字符*键)
{
std::map::it迭代器;
it=mMap2.find(键);
如果(it!=mMap2.end())
{
return(it->second).c_str();
}
返回NULL;
}
int initMap()
{
int-retVal=0;
int i=0;
对于(i=0;i 下面是上述代码的简化版本,它根本不在AIX上编译#include#include#include#include#include使用名称空间std;std::map myMap;int testFunc(){int retVal=0;std::string key(“key”);std::string value(“value”);myMap.insert(std::pair(key,value));retVal;}int main(){testFunc();返回0;}我注意到的一件事是,您应该使用#include
而不是string.h
。这可能是它找不到字符串的"/usr/vacpp/include/functional", line 155.29: 1540-0218 (S) The call does not match any parameter list for "operator<".
"/usr/vacpp/include/utility", line 92.14: 1540-1283 (I) "template <class _T1, class _T2> std::operator<(const pair<_T1,_T2> &, const pair<_T1,_T2> &)" is not a viable candidate.
"/usr/vacpp/include/functional", line 155.26: 1540-0288 (I) The function template parameter of type "const pair<_T1,_T2> &" cannot be initialized with an argument of type "const std::basic_string<char,std::char_traits<char>,std::allocator<char> >".
"/usr/vacpp/include/xutility", line 324.14: 1540-1283 (I) "template <class _Ty, class _D, class _Pt, class _Rt, class _Pt2, class _Rt2> std::operator<(const _Ptrit<_Ty,_D,_Pt,_Rt,_Pt,_Rt> &, const _Ptrit<_Ty,_D,_Pt2,_Rt2,_Pt,_Rt> &)" is not a viable candidate.
"/usr/vacpp/include/functional", line 155.26: 1540-0288 (I) The function template parameter of type "const _Ptrit<_Ty,_D,_Pt,_Rt,_Pt,_Rt> &" cannot be initialized with an argument of type "const std::basic_string<char,std::char_traits<char>,std::allocator<char> >".
"/usr/vacpp/include/xutility", line 470.14: 1540-1283 (I) "template <class _RI> std::operator<(const reverse_iterator<_RI> &, const reverse_iterator<_RI> &)" is not a viable candidate.
"/usr/vacpp/include/functional", line 155.26: 1540-0288 (I) The function template parameter of type "const reverse_iterator<_RI> &" cannot be initialized with an argument of type "const std::basic_string<char,std::char_traits<char>,std::allocator<char> >".
"/usr/vacpp/include/xtree", line 478.14: 1540-1283 (I) "template <class _Tr> std::operator<(const _Tree<_Tr> &, const _Tree<_Tr> &)" is not a viable candidate.
"/usr/vacpp/include/functional", line 155.26: 1540-0288 (I) The function template parameter of type "const _Tree<_Tr> &" cannot be initialized with an argument of type "const std::basic_string<char,std::char_traits<char>,std::allocator<char> >".
"/usr/vacpp/include/functional", line 154.14: 1540-0700 (I) The previous message was produced while processing "std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::operator()(const basic_string<char,std::char_traits<char>,std::allocator<char> > &, const basic_string<char,std::char_traits<char>,std::allocator<char> > &) const".
"/usr/vacpp/include/xtree", line 377.37: 1540-0700 (I) The previous message was produced while processing "std::_Tree<std::_Tmap_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,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::basic_string<char,std::char_traits<char>,std::allocator<char> > > >,0> >::find(const k...".
"t3.cpp", line 27.15: 1540-0700 (I) The previous message was produced while processing "getValue(const char *)".