-1
#ifndef NAME_H
#define NAME_H
#include <string> // For string class
class Name
{
private:
std::string first{};
std::string second{};
public:
Name(const std::string& name1, const std::string& name2) : first(name1), second(name2){}
Name()=default;
std::string get_first() const {return first;}
std::string get_second() const { return second; }
friend std::istream& operator>>(std::istream& in, Name& name);
friend std::ostream& operator<<(std::ostream& out, const Name& name);
};
// Stream input for Name objects
inline std::istream& operator>>(std::istream& in, Name& name)
{
return in >> name.first >> name.second;
}
// Stream output for Name objects
inline std::ostream& operator<<(std::ostream& out, const Name& name)
{
//My error is here while I am adding " " in the overload
return out << name.first << " " << name.second;
}
//我想重载< <运营商的std :: ostream的这需要在名称对象作为我的右手参数 //现在,当我添加了“”过载..它送给我的错误错误而运算符重载(错误:不对应的 '运营商<<'(操作数的类型是 '的std :: basic_ostream <char>' 和 '为const char [2]')
//错误是这样的: 错误:'操作符< <'(操作数类型是'std :: basic_ostream'和'const char [2]')不匹配 返回< < name.first < <“”< < name.second; ^
错误消息中有很多有用的信息。 – juanchopanza
你是什么意思? –
我的意思是读取错误信息,看看你的代码,并找出它。或者如果您需要帮助,请发布[mcve]并解释您遇到的问题。 – juanchopanza