标题:头文件编译错误问题
只看楼主
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
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册: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



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-332738-1-1.html




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

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