Проблемы компиляции карты AIX C++
Я не могу скомпилировать приведенный ниже код в AIX, в то время как Linux и Solaris, кажется, в этом отношении работают нормально Это дает мне проблемы с использованием C++ Map и пары ключей.
#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;
}
Ошибки также немного загадочны
"/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 *)".
Может кто-нибудь предложить, где я иду не так, или как я могу изменить код так, чтобы он был очень общим.
Я использую xlC++_r в AIX для его компиляции.
1 ответ
Вы должны иметь#include <string>
как правильный заголовок стандартной библиотеки вместо#include <string.h>
.