Nate Koppenhaver
Nate Koppenhaver

Reputation: 1702

Error using std::cout

When I try to print text to the Windows console (in a Console Application) I get
Compiler Error C2679 - Binary '<<' : no operator found which takes a right-hand operand of type 'std::basic_string<_Elem,_Traits,_Ax>' (or there is no acceptable conversion).
The code that generates this error is: (where str_var is any variable of type std::string)

std::cout << str_var << endl;

It highlights the first '<<' as the error. Could anybody help with this? I can't figure out why that doesnt work.

Upvotes: 2

Views: 1868

Answers (3)

Nate Koppenhaver
Nate Koppenhaver

Reputation: 1702

OK! problem solved! I reinstalled Visual Studio and now it works. So, it was just a problem with VS, not anything about the code.

Upvotes: 0

Sonny Saluja
Sonny Saluja

Reputation: 7287

I believe that you are missing:

#include <iostream>

Upvotes: 2

Mahesh
Mahesh

Reputation: 34665

Make sure string library is included and try


std::cout << str_var << std::endl ;

Upvotes: 0

Related Questions