0

How can i cout a string from char? For eg Vehicle 'C' is my char and is associated with car, i wAnt to cout car as output in different function. I have many more char like V, U, S, T for van , suv and so on. [on map] I have not yet learn it.

26th Sep 2016, 12:43 PM
Kris prototype
Kris prototype - avatar
2 Réponses
+ 3
use STL map. #include <iostream> #include <string> #include <map> using namespace std; int main() { map<char, string> CarMap; //set value for each cars CarMap['C'] = "car"; CarMap['V'] = "van"; CarMap['S'] = "suv"; //use at function when you just want to //"access" the value. cout << CarMap.at('C') << "\n"; return 0; }
26th Sep 2016, 12:55 PM
kiwiyou
kiwiyou - avatar
0
I havnt learn map yet
26th Sep 2016, 1:04 PM
Kris prototype
Kris prototype - avatar