在C++ STL中使用Map获取编译错误?

Ami*_*mar 0 c++ stl compiler-errors map

在下面的程序中使用MAP会产生一些编译器错误.没有得到他们的意思.

   #include <iostream>
   #include <cstdio>
   #include <map>
   #include <cstring>
  using namespace std;

  char maze [61][61], q;
  int n , m , i , j , x , y;
  map < char , char > left ;
  map < char , char > right ;
  char orient ;

   int main(){

   left ['N'] = 'W' ;
   left ['E'] = 'S';
   left['S'] = 'E';
   left['W'] = 'N';

   right['N'] = 'E';
   right['E'] = 'S';
   right['S'] = 'W';
   right['W'] = 'N';

     scanf( "%d %d" , &n , &m) ;

    for ( i = 0 ; i < n ; i++)
    scanf("%s", maze[i]);

    scanf("%d %d" , &x ,&y);
    orient = 'N' ;
    x = x - 1 ; y = y - 1 ;
    return 0 ;
   }
Run Code Online (Sandbox Code Playgroud)

获得编译错误如:

     prog.cpp: In function ‘int main()’:
     prog.cpp:15:1: error: reference to ‘left’ is ambiguous
                    left['N'] = 'W';

     prog.cpp:9:21: note: candidates are: std::map<char, char> left
                           map < char , char > left ;
            In file included from /usr/include/c++/4.8/ios:42:0,
             from /usr/include/c++/4.8/ostream:38,
             from /usr/include/c++/4.8/iostream:39,
             from prog.cpp:1:   /usr/include/c++/4.8/bits/ios_base.h:916:3:
              note:      std::ios_base& std::left(std::ios_base&)
              left(ios_base& __base)
Run Code Online (Sandbox Code Playgroud)

有什么问题可以指出,这意味着什么?有关详细信息,请访问:http:
//ideone.com/CqBiS0

awe*_*oon 9

具有名称leftright 已存在ios标题中的函数.他们是IO操纵者.

所以,这就是为什么你应该使用显式的命名空间解析而不是只写using namespace std.当然,您应该避免使用全局变量.