| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 749 人关注过本帖
标题:头文件编译错误问题
只看楼主 加入收藏
sixmore
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-1-26
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:2 
头文件编译错误问题
编译这样一个头文件时,提示红色行有很多错误
 #ifndef GUARD_split
 #define GUARD_split
 #include<vector>
 #include<string>
 std::vector<string> split( const std::string&);
#endif

接着 加了一句 using namespace std;编译就没问题了, 分析应该是std::string有问题,请问应该怎么修改才行?
 #ifndef GUARD_split
 #define GUARD_split
 #include<vector>
 #include<string>
 using namespace std;
 vector<string> split( const string&);
 #endif
搜索更多相关主题的帖子: include 
2011-02-24 23:38
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9008
专家分:53957
注 册:2011-1-18
收藏
得分:5 
std::vector<string> split( const std::string&);
改为
std::vector<std::string> split( const std::string&);

另外,最重要的是,你应该贴出编译器给出的错误信息以供别人参考。
2011-02-25 08:23
homelove
Rank: 2
来 自:厦门
等 级:论坛游民
帖 子:19
专家分:84
注 册:2010-12-21
收藏
得分:5 
标准c++中的所有类都存放在命名空间std里面。所以有两种修改方案,
一种是在每个类前面都显示加上std命名空间:如std::vector   std::string
另一种,是在开头先声明使用std, 如using namespace std;然后就可以在文件中直接用vector或string
一般采用第2种方案。
方案一:
程序代码:
#ifndef GUARD_split
#define GUARD_split
#include<vector>
#include<string>
std::vector<std::string> split( const std::string&);
#endif
方案二:
程序代码:
#ifndef GUARD_split
#define GUARD_split
#include<vector>
#include<string>
using namespace std;
vector<string> split( const string&);
#endif


2011-02-25 09:56
快速回复:头文件编译错误问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017829 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved