兄弟你好!
我在做一个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可以访问节点的第二部分数据区???
我测试确不行。为什??谢谢
我在做一个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可以访问节点的第二部分数据区???
我测试确不行。为什??谢谢
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)
map<CString,CString,less<CString>>
后面的>>中间加个空格就行了。
map<CString,CString,less<CString>空格>::iterator pIter ;
#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
http://support.microsoft.com/default.aspx?scid=kb;en-us;143207
我记的map的迭代器有一个方法:
pIter.First 可以访问节点的第一部分数据区???
pIter.Second可以访问节点的第二部分数据区???
我测试确不行。为什??
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.
------------------------------------------
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'
#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;
}
}
(*pIter).firstr
pIter->firstr