【发布时间】:2015-08-18 22:35:48
【问题描述】:
这里是代码
#include <iostream>
#include <string>
#include "char.h"
#include "user.h"
bool user::readYN (string ans)
{
ans = tolower (ans);
if (ans == "y" || ans == "yes")
{
return true;
}
else if (ans == "n" || ans == "no")
{
return false;
}
else
{
std::cout<<playr.inputErr;
return false;
}
}
字符串 ans 是从我的 main.cpp 传递给它的,应该是 y\n 以确认字符名称。但是,每当我尝试编译时,我都会收到错误
user.cpp:6: '{'之前的解析错误
和错误的人
user.cpp:8: '+' 之前的解析错误
我不知道它在哪里得到了 { 的错误,我不知道它在哪里看到 +(我的想法是平等的......也许???)我所有其他代码都已编译,我只是想要开始实际构建东西。
编辑:根据请求,头文件如下
用户.h
#ifndef user
#define user
#include<string>
class user
{
public:
string input;
static string inputErr;
bool readYN(string);
void read(string);
}playr;
#endif
和 char.h
#ifndef chara
#define chara
#include<string>
class charecter
{
public:
string name;
bool yes;
int HP;
void nameMe(string);
}chara;
#endif
【问题讨论】:
-
尝试用 std::string 替换字符串
-
您发布的代码中没有
+。您确定您发布了正确的代码吗? -
是的,我复制粘贴了它。为什么我对它在那里感到困惑
-
也许
tolower用作宏? AFAIKtolower可以得到char而不是字符串。是的,你错过了namespace std。 -
@ArtoriusIV
#include "char.h" #include "user.h"这些非标准头文件可能有问题。但不幸的是你没有透露:-( ...
标签: c++ compiler-errors