Try:
#include <unordered_map>
#include <iostream>
#include <string>
using namespace std;
int main() {
unordered_map<string, string> obj;
obj["test"] = "aaaa";
string var = "test";
cout << obj[var] << endl;
}
This is not exactly the same as the test string in both cases. If the difference between a “test” and a simple test is important, then the answer becomes a little more complicated.
See also: How to choose a map and unordered_map? to explain the discussion in the comments.
source
share