From: Alex Blekhman on 17 Jun 2007 06:45 aarthi28(a)gmail.com wrote: > I have written this code, and at the end, I am trying to write a > vector of strings into a text file. However, my program is nor > compiling, and it gives me the following error when I try to write to > the file: > > error C2679: binary '<<' : no operator found which takes a right-hand > operand of type 'std::string' (or there is no acceptable conversion) > > I don't know what I am doing wrong. I have posted my entire program > here. > Thank you > > #include <iostream> > #include <fstream> > #include <iterator> > #include <algorithm> > #include <vector> > #include <math.h> > #include "string.h" You forgot #include <string>. Alex
From: Alex Blekhman on 19 Jun 2007 05:05 Tim Roberts wrote: >> You forgot #include <string>. > > 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 > "std::string". > > So, the compiler has PART of std::string, but not all? 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 <string>. Alex
|
Pages: 1 Prev: MSMQ Next: _CrtIsValidHeapPointer Assertion in C++/CLI Application Debug mode. |