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

后端 未结 4 1669
情深已故
情深已故 2020-12-25 12:14

Please don\'t confuse with the title as it was already asked by someone but for a different context

The below code in Visual C++ Compiler (VS2008) d

相关标签:
4条回答
  • 2020-12-25 12:40

    Adding to @sbi answer, in my case the difference was including <string> instead of <string.h> (under VS 2017).

    See the following answer: similar case answer

    0 讨论(0)
  • 2020-12-25 12:42

    include <string>

    Try including string header file along with <iostream> file. It will work in some compilers even without the <string> because settings for different compilers are different and it is the compiler that is responsible for reading the preprocessor files that start with '#' symbol to generate a obj file.

    0 讨论(0)
  • 2020-12-25 12:44

    Have you included all of the following headers?

    • <fstream>
    • <istream>
    • <iostream>
    • <string>

    My guess is you forgot <string>.

    On a side note: That should be std::cout and std::endl.

    0 讨论(0)
  • 2020-12-25 12:53

    In addition to what others said. The following code was necessary in my application to compile succesfully.

    std::cout << s.c_str() << std::endl;
    

    Another work-around to this is go to project properties -> General -> Character Set and choose "Ues Multi-Byte Character Set" (You won't need to use c_str() to output the string)

    There's disadvantages to using MBCS so if you plan to localize your software, I'd advize against this.

    0 讨论(0)
提交回复
热议问题