首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

STL 地图 报错:error C2143: syntax error : missing '' before '<

2013-10-31 
STL map 报错:error C2143: syntax error : missing '' before ''#ifndef __P35_H_

STL map 报错:error C2143: syntax error : missing ';' before '<'

#ifndef __P35_H__
#define __P35_H__

#include <IOSTREAM>
#include <MAP>
#include <algorithm>

struct CidToId
{
int cid;
int cmt;//cid make time
};

CidToId cidtoid;

typedef map <int, cidtoid> Map_CidToServerId;
typedef map <int, Map_CidToServerId> Map_TidToCid;

Map_TidToCid map_tidtocid;
Map_TidToCid::iterator  it_tidtocid;
Map_CidToServerId::iterator it_cidtoserverid;

InsertTid(int tid, int cid);

#endif

e:\my file\hello world\p35\p35.h(16) : error C2143: syntax error : missing ';' before '<'
e:\my file\hello world\p35\p35.h(16) : error C2143: syntax error : missing ';' before '<'
e:\my file\hello world\p35\p35.h(17) : warning C4091: 'typedef ' : ignored on left of 'int' when no variable is declared
e:\my file\hello world\p35\p35.h(17) : error C2143: syntax error : missing ';' before '<'
e:\my file\hello world\p35\p35.h(17) : error C2143: syntax error : missing ';' before '<'
e:\my file\hello world\p35\p35.h(19) : error C2146: syntax error : missing ';' before identifier 'map_tidtocid'
e:\my file\hello world\p35\p35.h(19) : error C2501: 'Map_TidToCid' : missing storage-class or type specifiers
e:\my file\hello world\p35\p35.h(19) : fatal error C1004: unexpected end of file found
一下的.cpp供大家参考:
InsertTid(int tid, int cid, int sip)
{
int i = 0;

if(map_tidtocid.end() == (it_tidtocid = map_tidtocid.find(tid)))//tid find fail
{
map_tidtocid[tid];//insert tid
it_tidtocid = map_tidtocid.find(tid);//iterator
}

if(it_tidtocid->second.end() == (it_cidtoserverid = it_tidtocid->second.find(sip)))//find cid fail
{
it_tidtocid->second[sip];//insert cid
it_cidtoserverid = it_tidtocid->second.find(sip);
it_cidtoserverid->second.cid = cid;
it_cidtoserverid->second.cmt = (int)time(NULL);
}
else
{
it_cidtoserverid->second.cid = cid;
it_cidtoserverid->second.cmt = (int)time(NULL);
}
}
stl map algorithm struct c
[解决办法]
typedef map <int, Cidtoid> Map_CidToServerId;
[解决办法]
typedef?map?<int,?cidtoid>?Map_CidToServerId;
[解决办法]
CidToId cidtoid; 
typedef map <int, cidtoid> Map_CidToServerId;


map<int,CidToId>  -->map<T1,T2>  是类型,你直接用对象...
[解决办法]
#ifndef __P35_H__
#define __P35_H__
 
//#include <IOSTREAM>
//#include <MAP>
#include <iostream>
#include <map>
#include <algorithm>

using std::map;

.....

[解决办法]
InsertTid(int tid, int cid); 这是函数? 咋没返回类型
[解决办法]

#ifndef __P35_H__
#define __P35_H__ 
#include <IOSTREAM>
#include <MAP>
#include <algorithm> 
struct CidToId
{   
int cid;   
int cmt;//cid make time
}; 
CidToId cidtoid; 
typedef map <int, CidToId> Map_CidToServerId;
typedef map <int, Map_CidToServerId> Map_TidToCid; 
Map_TidToCid map_tidtocid;
Map_TidToCid::iterator  it_tidtocid;
Map_CidToServerId::iterator it_cidtoserverid; 
void InsertTid(int tid, int cid); 
#endif

void InsertTid(int tid, int cid, int sip)
{   
int i = 0;  
if(map_tidtocid.end() == (it_tidtocid = map_tidtocid.find(tid)))//tid find fail   


{       
map_tidtocid[tid];//insert tid      
it_tidtocid = map_tidtocid.find(tid);//iterator  
}   
if(it_tidtocid->second.end() == (it_cidtoserverid = it_tidtocid->second.find(sip)))//find cid fail  
{       
it_tidtocid->second[sip];//insert cid      
it_cidtoserverid = it_tidtocid->second.find(sip);  
it_cidtoserverid->second.cid = cid;     
it_cidtoserverid->second.cmt = (int)time(NULL);  
}    
else   
{       
it_cidtoserverid->second.cid = cid;    
it_cidtoserverid->second.cmt = (int)time(NULL);  
}
return;
}


[解决办法]
你那代码编译的时候 
1>e:\demo\demo\stdafx.h(103): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>e:\demo\demo\stdafx.h(107): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>e:\demo\demo\stdafx.h(126): warning C4508: 'InsertTid' : function should return a value; 'void' return type assumed
报错直接就找到 没返回类型啊
[解决办法]
引用:
Quote: 引用:

CidToId cidtoid; 
typedef map <int, cidtoid> Map_CidToServerId;


map<int,CidToId>  -->map<T1,T2>  是类型,你直接用对象...

我修改了类型,报错还是一样啊。甚至我修改成了
typedef map <int, int> Map_CidToServerId;

还是一样的报错。


加上名字空间
//typedef map <int, int> Map_CidToServerId;
typedef std::map <int, int> Map_CidToServerId;


[解决办法]
.......难道你们都没看出来是没有加using std::map吗?
改成这样,应该就ok了:
typedef std::map <int, CidToId> Map_CidToServerId;

热点排行