quiero definir algo comomatriz de caracteres como un valor en el mapa C++
Map<int, char[5] > myMap;
La declaración anterior es aceptado por el compilador de C++ y no hay error se lanza, pero cuando hago algo como esto
int main()
{
char arr[5] ="sdf";
map <int, char[5]> myMap;
myMap.insert(pair<int, char[5]>(0,arr));
return 0;
}
me sale error como:
In file included from /usr/include/c++/4.6/bits/stl_algobase.h:65:0,
from /usr/include/c++/4.6/bits/char_traits.h:41,
from /usr/include/c++/4.6/ios:41,
from /usr/include/c++/4.6/ostream:40,
from /usr/include/c++/4.6/iostream:40,
from charMap.cpp:1:
/usr/include/c++/4.6/bits/stl_pair.h: In constructor ‘std::pair<_T1, _T2>::pair(const _T1&, const _T2&) [with _T1 = int, _T2 = char [5]]’:
charMap.cpp:9:42: instantiated from here
/usr/include/c++/4.6/bits/stl_pair.h:104:31: error: array used as initializer
/usr/include/c++/4.6/bits/stl_pair.h: In constructor ‘std::pair<_T1, _T2>::pair(const std::pair<_U1, _U2>&) [with _U1 = int, _U2 = char [5], _T1 = const int, _T2 = char [5]]’:
charMap.cpp:9:43: instantiated from here
/usr/include/c++/4.6/bits/stl_pair.h:109:39: error: array used as initializer
es importante para mí definir una matriz de caracteres de tamaño fijo becau se optimiza la operación de mi red de flujo. ¿Hay alguna forma de lograrlo? No quiero usar char *
o std::string
.
¿Usted ha intentado definir un 'struct' que contiene un' char [5] '? – OmnipotentEntity
¿Por qué no 'char *' o mejor aún 'string'? –
@OmnipotentEntity, sí, pude hacerlo convirtiéndolo en una estructura :) Pero, ¿pueden explicarme por qué fue un trabajo estructural y no el mismo [5]? –