I am trying to use a for statement with a vector in a vector.
std::vector<std::string> array = {
{"A", "a"},
{"B", "b"},
{"C", "c"}
};
for (std::string& a : array) {
if (letter == a[1] || letter == a[0]) {
std::cout << a[0] << ": " << a[1] << std::endl;
break;
}
}
I am new to C++ and cannot figure out why it gives me errors about this.
Edit:
Error: error: invalid operands to binary expression ('std::string' (aka 'basic_string<char>') and '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' (aka 'char'))
>Solution :
I think {"A", "a"} is already a verctor, and this array varable type should be vector<vector<string>>.