error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) - David Lowndes |
17-Jun-07 06:17:53
|
Try adding .c_str():
out_a << achar.c_str() << endl;
Dave |
 |
| |
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) - Alex Blekhman |
17-Jun-07 06:45:07
|
You forgot #include <string>.
Alex |
 |
| |
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) - Tim Roberts |
19-Jun-07 02:12:41
|
OK, I admit I am confused. I cut and pasted his code to my local PC, and
in fact you are correct: #include <string> fixes it.
However, long before he tries to write the string to cout, we see this:
string achar, nchar;
int main(int argc, char* argv[])
vector<string> n_word_list;
vector<string> a_word_list;
all of which compiles successfully. Further, the error message (shown
above) clearly shows that the compiler knows that "string" means
So, the compiler has PART of std::string, but not all?
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc. |
 |
| |
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) - Alex Blekhman |
19-Jun-07 05:05:51
|
Yes, other standard headers can include <string> or forward
declare `std::string' for internal purposes. However, you
should not rely on it. In your specific case, `operator <<'
that writes `std::string' into a stream is declared inside
Alex |
 |
| |
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) - David Wilkinson |
19-Jun-07 09:28:44
|
Alex:
Without looking at the headers in detail, I would have to say that I am
still confused (for the same reason as Tim). But clearly you are
correct, <string> is missing.
This issue of missing headers is the single most common problem I find
in cross-platform work. I develop on VC7.1 and compile the same code
with gcc, and I quite often get missing header errors because VC has
allowed me to omit some header because (presumably) it is included in
some other header. Of course, the resolution is always to include the
correct headers, but this is not so easy when the code compiles without
them.
--
David Wilkinson
Visual C++ MVP |
 |
| |
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) - Alex Blekhman |
19-Jun-07 12:07:47
|
I don't have VC7.1 to check this case, but VC2005 compiles
and links it without any problem.
Anyway, `basic_string' is implemented in <xstring> header,
actually. Several standard headers include <xstring> either
directly or indirectly because of methods that return
`std::string' and/or accept it as a parameter. That's why
`std::string' is available in user's code too when something
like <iostream> or <exception> is included. However, I/O
operators that work with `std::string' are declared in
streams one can get away with working code without including
Implementation of other standard classes can be scattered
among several headers, too. It gives a developer an illusion
as if compiler "knows" partially about some classes.
I agree. That's why I insist on nightly cross-platform build
when I work on cross-platform a project. It helps to
pinpoint such problems early.
Alex |
 |
| |