STL card <line, line>, assigning a value of 0 to a key value causes a compilation error

I use the compiler class when using the map class and wrote the following simple program to highlight the error:

  1 #include <string>
  2 #include <map>
  3
  4 using namespace std;
  5
  6 int main()
  7 {
  8     map<string, string> testmap;
  9
 10
 11     testmap["one"] = 11;
 12     testmap["two"] = 22;
 13     testmap["zero"] = 0;
 14     // testmap["zero"] = 10;
 15
 16     return 0;
 17 }

I get the following compilation error:

g++./test.cc. /test.cc: 'int main()':. /test.cc:13:23: : 'operator =' 'testmap.std:: map < _Key, _Tp, _Compare, _Alloc > :: operator [], std:: basic_string, std:: less > , > std:: allocator, std:: basic_string → > ((* std:: basic_string (((const char *) "zero" ), ((const std:: allocator) (& std:: allocator()))))) = 0 '. /test.cc:13:23: : : , /usr/include/c ++/4.7/string:54:0,                 from./test.cc:1: /usr/include/c ++/4.7/bits/basic_string.h:543:7: note: std:: basic_string < _CharT, _Traits, _Alloc > & std:: basic_string < _CharT, _Traits, _Alloc > :: operator = (const std:: basic_string < _CharT, _Traits, _Alloc > &) [with > _CharT = char; _Traits = std:: char_traits; _Alloc = std:: allocator; std:: basic_string < _CharT, _Traits, _Alloc >= std:: basic_string] /usr/include/c ++/4.7/bits/basic_string.h:551:7: note: std:: basic_string < _CharT, _Traits, _Alloc > & std:: basic_string < _CharT, _Traits, _Alloc > :: operator = (const _CharT *) [ _CharT = char; _Traits = > std:: char_traits; _Alloc = std:: allocator; std:: basic_string < _CharT, _Traits, _Alloc >= std:: basic_string] /usr/include/c ++/4.7/bits/basic_string.h:562:7: note: std:: basic_string < _CharT, _Traits, _Alloc > & std:: basic_string < _CharT, _Traits, _Alloc > :: operator = (_ CharT) [ _CharT = char; _Traits = std:: char_traits; _Alloc = std:: allocator; std:: basic_string < _CharT, _Traits, _Alloc >= std:: basic_string]

: 1. , "" - 11 22 . , , . :   testmap [ "one" ] = 11;

  • 11, 22 , 0 .

  • , . , / string. -, , , .

.

, .

+4
1

11, 22 , 0 .

. 11 12 basic_string& operator=( CharT ch ); - 11 12 - -, , . , ala std::cout << testmap["one"]; - 11 " ", , 12 - " ", (. http://en.wikipedia.org/wiki/ASCII).

0 , ( ++ 03 NULL 0), (.. char const char*?) - . http://en.cppreference.com/w/cpp/string/basic_string/operator%3D std::string operator= s.

4.10 [conv.ptr] 1 (2.14.2) prvalue std:: nullptr_t. ;...

- .

:

  • , . std::to_string(), boost::lexical_cast, a std::ostringstream ..,
  • std::map<string, int> .
+13

All Articles