M. Eugen M. Eugen - 20 days ago 4x
C++ Question

Error C++ 2679 (binary '>>': no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion))

HI. Before my question, I've looked in other threads with same error, nothing worked for me.
My problem code is at

in >> a.name >> a.extension;
. As I tested myself, if I change the type from
for my variables, it will work, but I can't make it work with a
type of value.

Am I doing something wrong?
Below full error code on compillation (Visual Studio 2015)

Error C2679 binary '>>': no operator found which takes a right-hand
operand of type 'const std::string' (or there is no acceptable

Thanks in advance.

#include <iostream>
#include <ctime>
#include <string>
using namespace std;

class Soft {
int *size;
time_t *dateTime;
string name;
string extension;
Soft(string, string);
Soft(const Soft&source);

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;

return 0;


The key word here is const, which means that the thing cannot be modified.

You are trying to modify a const thing. You cannot do that.

Your function, like any operator>> in general, should be declared like this:

friend istream& operator>>(istream& in, Soft& a) 

The change I have made is to remove the const.

By the way, I see no reason at all for your member variables size and dateTime to be pointers to dynamically allocated integers. Your code will be much simpler if you just make them normal integers.