unpacking type

Using Visual Studio IDE, w/ ISO C++17 Standard (/std:c++17) as the compiler language option.

#include <iostream>
#include <map>

using namespace std;

1
2
3
4
5
6
7
8
9
10
11
12
13
int main()
{
  map<string, size_t> stooges_ranking{
    {"larry", 7},
    {"mo", 3},
    {"curly", 9},
    {"shemp", 8}
  };

  for (const auto & [name, rank] : stooges_ranking) {
    cout << name << " is ranked at " << rank << endl;
  }
}

The above results in a Compiler error:
E0349 no operator "<<" matches these operands
C2679 binary '<<': no operator found which takes a right=-hand operand of type 'const std::basic_string< char, std::char_traits<char>, std::allocator<char>>'

I'm surprised by the compiler not recognizing this.

If I use :
cout << name.c_str() ... then every thing is fine.
Can anybody explain why I'm getting this issue?
Last edited on
You didn't include <string>.
Topic archived. No new replies allowed.