Error: binary '<<' : no operator found which takes a right-hand operand of type 'std::string'
14,289
<cstring>
is the header for C strings, i.e, its content is the same as the C header string.h
. What you need to handle std::string
is <string>
Another problem is that you missed the semicolon:
using namespace std;
// ^
Note that this style works, but is not recommend, it's better not to use this line and use:
std::cout << std::endl << output << std::endl;
Author by
UberAffe
Updated on June 04, 2022Comments
-
UberAffe almost 2 years
My Question is similar to others but I wasn't able to find and answer that quite fit, maybe I'm just missing it, but anyways.
Given that this is at the top of my .cpp:
#include <cstring> #include <iostream> using namespace std
why would this line have an error:
cout << endl << output << endl;
the error being:
binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
-
zwol over 10 yearsOr even better,
std::cout << '\n' << output << '\n';
. With rare exceptions, needingendl
means your buffering is set incorrectly.