当我编译以下文件时,出现错误:

ECArgs.h:36:3: error: ‘string’ does not name a type

ECArgs.h:36: ECString 值(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;
};

字符串文件
#define ECS gnu

#if ECS == gnu
#include <cstring>
#define ECString string
using namespace std;
#else
#include <bstring.h>
#define ECString string
#endif

最佳答案

您需要添加:

#include <string>

cstring 包括操作 C 风格字符串的函数。此版本有效:
#include <list>
#include <string>

#if ECS == gnu
#include <cstring>
#define ECString string
using namespace std;
#else
#include <bstring.h>
#define ECString string
#endif

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;
};

int main()
{

}

10-07 18:26