HI。在我的问题之前,我查看了其他线程有同样的错误,没有为我工作。 我的问题代码是in >> a.name >> a.extension;
。当我测试自己时,如果我将变量的类型从string
更改为char
,它将起作用,但我无法使其与string
类型的值一起工作。错误C++ 2679(二进制'>>':找不到操作符需要'const std :: string'类型的右侧操作数(或者没有可接受的转换))
我做错了什么? 下面就compillation(Visual Studio的2015年)
错误C2679二进制“>>”完全错误代码:没有操作员发现这需要右手 数类型“字符串常量的std ::”的(或有不可接受 转换)
在此先感谢。这里
#include <iostream>
#include <ctime>
#include <string>
using namespace std;
class Soft {
private:
int *size;
time_t *dateTime;
public:
string name;
string extension;
Soft();
Soft(string, string);
Soft(const Soft&source);
~Soft();
friend istream& operator>> (istream& in, const Soft& a)
{
in >> a.name >> a.extension;
return in;
};
void changeName(string);
void changeExtension(string);
};
Soft::Soft() {
size = new int;
*size = 0;
name = string("");
extension = string("");
dateTime = new time_t;
*dateTime = time(nullptr);
}
Soft::Soft(const Soft&source) {
name = source.name;
extension = source.extension;
size = new int;
*size = *source.size;
dateTime = new time_t;
*dateTime = time(nullptr);
}
Soft::Soft(string a, string b) {
name = a;
extension = b;
dateTime = new time_t;
*dateTime = time(nullptr);
}
Soft::~Soft() {
delete[] size;
delete[] dateTime;
}
void Soft::changeExtension(string a) {
extension = a;
}
void Soft::changeName(string a) {
name = a;
}
int main() {
Soft a;
getchar();
getchar();
return 0;
}
我没有看到任何,但我的学校的老师希望与指针的一切......这是写明确使用指针所有变量 –
@ M.Eugen:这是可笑的。你被教导如何做错了。 :( –
@LightnessRacesinOrbit:你没有学到的东西“可变”关键字呢?他可以宣布他的会员数据,可变的,那么他的例子将正常工作 – Raindrop7