c++ - '' *2之前的解析错误

这是代码

#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: parse error before '{'



和错误的

user.cpp:8: parse error before '+'



我不知道 { 哪里出错了,我不知道它在哪里看到 +(我的想法是平等的......也许???)我所有其他代码都已编译,我只想开始实际上是在 build 东西。

编辑:通过请求头文件如下

用户.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

最佳答案

改变

bool user::readYN (string ans)


bool user::readYN (std::string ans)

关于c++ - '' *2之前的解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32083700/

相关文章:

c++ - 默认构造函数编译错误,预期的ID不合格

android - Android代码抛出错误

java - 无法编译Java代码

java - 未知的Java类错误

c++ - 编译用户定义的类时出现编译器错误

exception - 捕获 block 避免编译错误?

c++ - 模板化 BST 方法的返回值问题

oracle - Oracle函数编译错误PLS-00103(遇到符号 “SELECT”…)

java - 出现错误: No enclosing instance of type **** is

javascript - 我收到“无效的作业左侧