当我编译以下文件时,出现了错误:
ECArgs.h:36:3: error: ‘string’ does not name a type
ECArgs.h:36: ECString value(char c);
请问有人能给我提示这个错误的解决方法吗?
ECArgs.h
#include <list>
#include "ECString.h"
class ECArgs
{
public:
ECArgs(int argc, char *argv[]);
int nargs() { return nargs_; }
bool isset(char c);
ECString value(char c);
ECString arg(int n) { return argList[n]; }
private:
int nargs_;
int nopts_;
ECString argList[32];
list<ECString> optList;
};
ECString.h
#define ECS gnu
#if ECS == gnu
#include <cstring>
#define ECString string
using namespace std;
#else
#include <bstring.h>
#define ECString string
#endif
typedef
和using
比#define
更好地解决了类型别名的问题。 - chrisstd::string
,你需要使用#include <string>
,而不是#include <cstring>
。 - jogojapanstd::string
在<string>
中,并且你从未引入它。因此,编译器在抱怨时是完全合理的。 - chris#if ECS == gnu
做了你想做的事情吗?它将ECS
和gnu
作为整数常量表达式进行评估。gnu
是如何定义的? - Keith Thompson