兄弟你好!
 
 我在做一个map容器。在申明的时候老是报错。请兄弟帮忙:谢谢
申明如下:
#include <map> 
using namespace std//------------------
map<CString,CString,less<CString>> pMyMap ;
map<CString,CString,less<CString>>::Iterator pIter ;
就这些:编译器报了20个错误:
: error c2061:syntax error: indentifier 'THIS_FILE': 
: error c2091:function returns function 
: error c2809:'operator new'has no formal paramerters 
...
象是STL的错误。
第二个问题:
    我记的map的迭代器有一个方法:
pIter.First 可以访问节点的第一部分数据区???
pIter.Second可以访问节点的第二部分数据区???
我测试确不行。为什??谢谢

解决方案 »

  1.   

    using namespace std;//后面要加上分号
      

  2.   

    #include <map>
    using namespace std ;
    //-------------------------------------------------错误信息
    Compiling...
    testmm.cpp
    e:\microsoft visual studio\vc98\include\new(35) : error C2061: syntax error : identifier 'THIS_FILE'
    e:\microsoft visual studio\vc98\include\new(35) : error C2091: function returns function
    e:\microsoft visual studio\vc98\include\new(35) : error C2809: 'operator new' has no formal parameters
    e:\microsoft visual studio\vc98\include\new(36) : error C2061: syntax error : identifier 'THIS_FILE'
    e:\microsoft visual studio\vc98\include\new(37) : error C2091: function returns function
    e:\microsoft visual studio\vc98\include\new(37) : error C2556: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,const struct std::nothrow_t &)' : overloaded function differs only by return type from 'void *(__cdecl *__cdecl operator new(voi
    d))(unsigned int)'
            e:\microsoft visual studio\vc98\include\new(35) : see declaration of 'new'
    e:\microsoft visual studio\vc98\include\new(41) : error C2061: syntax error : identifier 'THIS_FILE'
    e:\microsoft visual studio\vc98\include\new(42) : error C2091: function returns function
    e:\microsoft visual studio\vc98\include\new(42) : error C2556: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,void *)' : overloaded function differs only by return type from 'void *(__cdecl *__cdecl operator new(void))(unsigned int)'
            e:\microsoft visual studio\vc98\include\new(35) : see declaration of 'new'
    e:\microsoft visual studio\vc98\include\new(42) : error C2809: 'operator new' has no formal parameters
    e:\microsoft visual studio\vc98\include\new(42) : error C2065: '_P' : undeclared identifier
    e:\microsoft visual studio\vc98\include\memory(16) : error C2061: syntax error : identifier 'THIS_FILE'
    e:\microsoft visual studio\vc98\include\memory(17) : error C2091: function returns function
    e:\microsoft visual studio\vc98\include\memory(17) : error C2784: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,class std::allocator<`template-parameter257'> &)' : could not deduce template argument for 'void *(__cdecl *)(unsigned int,cl
    ass std::allocator<_Ty> &)' from 'void *(__cdecl *)(unsigned int)'
    e:\microsoft visual studio\vc98\include\memory(17) : error C2785: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,class std::allocator<`template-parameter257'> &)' and 'void *(__cdecl *__cdecl operator new(void))(unsigned int)' have differ
    ent return types
            e:\microsoft visual studio\vc98\include\memory(16) : see declaration of 'new'
    e:\microsoft visual studio\vc98\include\memory(17) : error C2809: 'operator new' has no formal parameters
    e:\microsoft visual studio\vc98\include\memory(20) : error C2954: template definitions cannot nest
    Error executing cl.exe.testmm.exe - 17 error(s), 0 warning(s)
      

  3.   

    简单:
    map<CString,CString,less<CString>> 
    后面的>>中间加个空格就行了。
      

  4.   

    map<CString,CString,less<CString>空格> pMyMap ;
        map<CString,CString,less<CString>空格>::iterator pIter ;
      

  5.   

    把你的这段代码
    #include <map> 
    using namespace std//------------------
    map<CString,CString,less<CString> > pMyMap ;
    map<CString,CString,less<CString> >::Iterator pIter ;放在下面的代码之上#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
      

  6.   

    具体解释,请参考以下文档:
    http://support.microsoft.com/default.aspx?scid=kb;en-us;143207
      

  7.   

    第二个问题:
        我记的map的迭代器有一个方法:
    pIter.First 可以访问节点的第一部分数据区???
    pIter.Second可以访问节点的第二部分数据区???
    我测试确不行。为什??
      

  8.   

    不是First、Second,是first,second
      

  9.   


    map<CString,int,less<CString> > pMyMap ;
    map<CString,int,less<CString> >::iterator pIter ;
    pMyMap["Name"]=10 ;
    pMyMap["Age"]=30 ;
         
    pIter=pMyMap.begin() ; 
    pIter.firstr;--------------------Configuration: testmm - Win32 Debug--------------------
    Compiling...
    testmm.cpp
    E:\vc6.0\MSDev98\MyProjects\testmm\testmm.cpp(175) : error C2039: 'firstr' : is not a member of 'iterator'
            e:\microsoft visual studio\vc98\include\xtree(120) : see declaration of 'iterator'
    Error executing cl.exe.
      

  10.   

    pIter.first 
    ------------------------------------------
    E:\vc6.0\MSDev98\MyProjects\testmm\testmm.cpp(175) : error C2039: 'first' : is not a member of 'iterator'
            e:\microsoft visual studio\vc98\include\xtree(120) : see declaration of 'iterator'
      

  11.   

    #pragma warning(disable:4786)#include <iostream>
    #include <string>
    #include <map>using namespace std;
    typedef map<int, string, less<int> > INT2STRING;void main()
    {
    // 1. Create a map of ints to strings
        INT2STRING theMap;
        INT2STRING::iterator theIterator;
        string theString = "";
        int index;// Fill it with the digits 0 - 9, each mapped to its string counterpart
    // Note: value_type is a pair for maps...
        theMap.insert(INT2STRING::value_type(0,"Zero"));
        theMap.insert(INT2STRING::value_type(1,"One"));
        theMap.insert(INT2STRING::value_type(2,"Two"));
        theMap.insert(INT2STRING::value_type(3,"Three"));
        theMap.insert(INT2STRING::value_type(4,"Four"));
        theMap.insert(INT2STRING::value_type(5,"Five"));
        theMap.insert(INT2STRING::value_type(6,"Six"));
        theMap.insert(INT2STRING::value_type(7,"Seven"));
        theMap.insert(INT2STRING::value_type(8,"Eight"));
        theMap.insert(INT2STRING::value_type(9,"Nine"));// Read a Number from the user and print it back as words
        for( ; ; )
        {
            cout << "Enter \"q\" to quit, or enter a Number: ";
            cin >> theString;
            if(theString == "q")
                break;
            // extract each digit from the string, find its corresponding
            // entry in the map (the word equivalent) and print it
            for(index = 0; index < theString.length(); index++){
                theIterator = theMap.find(theString[index] - '0');
                if(theIterator != theMap.end() )    // is 0 - 9
                    cout << (*theIterator).second << " ";
                else    // some character other than 0 - 9
                    cout << "[err] ";
            }
            cout << endl;
        }
    }
      

  12.   

    晕,什么pIter.firstr啊,应该是(*pIter).firstr!
      

  13.   

    本来以为能挣点分了,想不到有人回答了
    (*pIter).firstr
    pIter->firstr