语法错误:缺少';'标识
之前,我是新来的C++,要调试的代码语法错误:缺少';'标识
class cGameError
{
string m_errorText;
public:
cGameError(char *errorText)
{
DP1("***\n*** [ERROR] cGameError thrown! text: [%s]\n***\n",
errorText);
m_errorText = string(errorText);
}
const char *GetText()
{
return m_errorText.c_str();
}
};
enum eResult
{
resAllGood = 0, // function passed with flying colors
resFalse = 1, // function worked and returns 'false'
resFailed = –1, // function failed miserably
resNotImpl = –2, // function has not been implemented
resForceDWord = 0x7FFFFFFF
};
这个头文件中的以下行包括在程序作为遵循
#include "string.h"
#include "stdafx.h"
#include "Chapter 01 MyVersion.h"
#include "cGameError.h"
您需要包括<串>,不是“string.h”。或者除了“string.h”。
string.h中是标准C字符串处理函数的C头(的strcpy()和朋友。)
<串>是标准C++头,其中 '字串' 被定义。
您还需要使用字符串时指定std命名空间:
std::string m_errorText;
或使用:
using namespace std;
在某处你的文件的顶部。
您还应该为系统包含文件使用尖括号。
你已经提供了足够的信息很少,这只是胡乱猜测,但乍一看,我猜问题是,你还没有包括<string>
,只有"string.h"
(前者定义了C++ std::string
类,用于操纵空终止字符串后者的C函数。
顺便说一句,通常要使用角括号用于系统头,所以它应该是<string.h>
。
实际上,“string.h”不是* any *标准的一部分 - 当您将标头名称括在引号中时,仅在* current目录中搜索文件*。 – 2010-05-22 16:38:48
@Stefan:不是。首先以实现定义的方式(通常是当前目录)搜索,如果失败,则重新处理,如同使用尖括号(C99,§6.10.2/ 3,C++ 03§16.2/ 3)一样。 – 2010-05-22 16:52:20
啊,好的。我懂了。 – 2010-05-22 17:08:24
尝试#include <string>
,代替#include "string.h"
,串.h/cstring是旧的C字符串标题,字符串是新的C++ std::string
类头。你通常使用角括号来表示系统头文件。
是的,还需要名称空间标准; – numerical25 2010-05-22 16:37:21