关于STL中的map使用求解

ljlln 2004-07-11 01:25:35
兄弟你好!

我在做一个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可以访问节点的第二部分数据区???
我测试确不行。为什??

谢谢
...全文
209 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
maxcode 2004-07-12
  • 打赏
  • 举报
回复
map<CString,CString,less<CString>空格> pMyMap ;
map<CString,CString,less<CString>空格>::iterator pIter ;
skyMountain 2004-07-12
  • 打赏
  • 举报
回复
不加空格,系统会认为那是一个输入输出符的。
skyMountain 2004-07-12
  • 打赏
  • 举报
回复
简单:
map<CString,CString,less<CString>>
后面的>>中间加个空格就行了。
ljlln 2004-07-12
  • 打赏
  • 举报
回复
#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)
ljlln 2004-07-12
  • 打赏
  • 举报
回复
加上还不行。
QunKangLi 2004-07-12
  • 打赏
  • 举报
回复
using namespace std;//后面要加上分号
ljlln 2004-07-12
  • 打赏
  • 举报
回复
兄弟们帮忙
ljlln 2004-07-12
  • 打赏
  • 举报
回复
谢谢
Mutalisk 2004-07-12
  • 打赏
  • 举报
回复
本来以为能挣点分了,想不到有人回答了
(*pIter).firstr
pIter->firstr
jazy 2004-07-12
  • 打赏
  • 举报
回复
iterator是指针,用->
skyMountain 2004-07-12
  • 打赏
  • 举报
回复
晕,什么pIter.firstr啊,应该是(*pIter).firstr!
落入凡间的猪 2004-07-12
  • 打赏
  • 举报
回复
#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;
}
}
ljlln 2004-07-12
  • 打赏
  • 举报
回复
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'
ljlln 2004-07-12
  • 打赏
  • 举报
回复

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.

bluwindhrt 2004-07-12
  • 打赏
  • 举报
回复
不是First、Second,是first,second
ljlln 2004-07-12
  • 打赏
  • 举报
回复
第二个问题:
我记的map的迭代器有一个方法:
pIter.First 可以访问节点的第一部分数据区???
pIter.Second可以访问节点的第二部分数据区???
我测试确不行。为什??
落入凡间的猪 2004-07-12
  • 打赏
  • 举报
回复
具体解释,请参考以下文档:
http://support.microsoft.com/default.aspx?scid=kb;en-us;143207

落入凡间的猪 2004-07-12
  • 打赏
  • 举报
回复
或者直接放在.h文件中
落入凡间的猪 2004-07-12
  • 打赏
  • 举报
回复
把你的这段代码
#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

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧