Alternatively, you could use std::vector< std::pair< char, char > >
.
Note, that you cannot use operator[]
(ie. call arr[0]
or arr[0][0]
on an empty vector (since the requested elements are not there, you access invalid memory which (hopefully) will crash your program). Add elements to a vector with push_back(...)
:
vector< pair< char, char > > arr;
arr.push_back( make_pair( 'à','á' ) );
arr.push_back( make_pair( 'è','é' ) );
arr.push_back( make_pair( 'ì','í' ) );
arr.push_back( make_pair( 'ò','ó' ) );
arr.push_back( make_pair( 'ò','ó' ) );
arr.push_back( make_pair( 'ù','ú' ) );
Depending on what you want to do, std::map< char, char >
might be useful for you as well. It will allow you to access elements using the first type as a key, eg.
std::map<char, char > mymap;
mymap['à'] = 'á';
// will print "Element à = à"
cout << "Element à = " << mymap['à'] << endl;