C++ 错误:“字符串”未命名类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15194395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C++ errors: ‘string’ does not name a type
提问by Xing Shi
when I compile the following files, I've got the error:
当我编译以下文件时,出现错误:
ECArgs.h:36:3: error: ‘string' does not name a type
ECArgs.h:36: ECString value(char c);
ECArgs.h:36: ECString 值(char c);
Could somebody give me any hints for the error?
有人可以给我任何关于错误的提示吗?
ECArgs.h
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
采纳答案by Shafik Yaghmour
You need to add:
您需要添加:
#include <string>
cstringincludes function to manipulate C-style string. This version works:
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()
{
}
回答by Selah
I ran into a similar error. It was due to the fact that I had left out using namespace std;
我遇到了类似的错误。那是因为我遗漏了using namespace std;