C++错误(操作数类型为"std::string 和 'void")
C++ Error (operand types are 'std::string and 'void')
我是c++编程新手。所以,如果我在提问时犯了很多错误,请向我道歉。
我的问题是
创建一个包含私有变量和方法的类,如下所示:
class Records{
private:
string name;
public:
string n;
void setValue(){
cout << "Enter name" << endl;
cin >> name;
}
void getValue(){
n = name;
cout << "Name is: " << n << endl;
}
};
我有运行你的代码在GCC编译器上,它成功地工作了。请参阅完整示例:
#include <iostream>
using namespace std;
class Records{
private:
string name;
public:
string n;
void setValue(){
cout << "Enter name" << endl;
cin >> name;
}
void getValue(){
n = name;
cout << "Name is: " << n << endl;
}
};
int main()
{
Records r;
r.setValue();
r.getValue();
}
相关文章:
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- 与'operator='不匹配(操作数类型'String'且"void")
- 错误:"cast"未命名类型void setCastDescription(std::string
- Arduino trim() 和 replace() 方法返回从 'void' 到非标量类型'String'请求的转换
- 如何将 std::string 作为构造函数参数传递,并将其保存的 C 字符串存储在 void 指针中?
- 如何将 std::string 赋回作为 <char>void* 指针传递的 std::vector.data()?
- 从 'void *' 转换为 'const std::string *&' 必须具有所有中间指针 const 合格
- "conversion from void to non scalar type string"是什么意思?
- 为什么"std::vector<std::string> &"而不是"void"?
- "expected unqualified-id before 'void'" & "string in class does not name a type" 错误
- *&在这里做什么?如何更改它以获取代码作为 void binaryTree::insert(binaryNode *root,string value)?可能吗?
- 函数void()返回一个值,而不是char或string
- C++ 为什么要使用从 (std::string) 到 (void) 类型的隐式转换
- 将 std::function<void(string, string)> 转换为通用 std::function<void()>
- 将内联加速 void a(string b) { cout << b; }
- 将 std::vector<std::string> 转换为 void*
- 将 bool[] 转换为 std::string 的 void*
- C++错误(操作数类型为"std::string 和 'void")
- std::unordered_map<std::string,std::function<void(std::string&) 只能容纳静态函数吗?
- 错误:参数太少,无法函数"void alpha(std::string*,student)"