我有一个问题,示例代码将在代码块环境中编译和运行,但不会在 Visual Studio 2012 中编译
list<string> names;
names.push_back("Mary");
names.push_back("Zach");
names.push_back("Elizabeth");
list<string>::iterator iter = names.begin();
while (iter != names.end()) {
    cout << *iter << endl;  // This dereference causes compile error C2679
    ++iter;
}
导致以下编译器错误
1>chapter_a0602.cpp(20): error C2679: binary '<<' : no operator found which takes a
right-hand operand of type 'std::basic_string<_Elem,_Traits,_Alloc>' (or there is no
acceptable conversion)
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Alloc=std::allocator<char>
1>          ]
当我将字符串列表更改为整数列表时,代码会在 VS2012 中编译并运行。
当我还将取消引用更改为以下内容时,它会编译
cout << *the_iter->c_str() << endl;
但是我在代码后面还有另外两个取消引用问题
cout << "first item: " << names.front() << endl;
cout << "last item: "  << names.back() << endl;
我真的不明白为什么这些错误取决于编译器。
对格式感到抱歉,但我无法让它接受代码。