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.
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;
}
0
I havnt learn map yet