none
Strange Error; IOSTREAM has suddenly "lost" the >> operator (doesn't run with 'std::cin >>' for user input)

    Question

  • Hello,

    I am a noobi beginner, but have a serious question. I apologize if this is a boring fix. I use Visual Studio, and when I type the following text below and run the program, the following error comes up:

    "There were build errors. Would you like to continue and run the last successful build?"

    I type NO and the Output tab shows:

    1>------ Build started: Project: PROJECT, Configuration: Debug Win32 ------
    1>SourceG.cpp
    1>c:\users\MYCOMPUTER\source\repos\PROJECT\PROJECT\sourceg.cpp(8): error C2679: binary '>>': no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
    1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\istream(333): note: could be 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(std::basic_streambuf<char,std::char_traits<char>> *)'
    1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\istream(328): note: or       'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(void *&)'
    1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\istream(323): note: or       'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(long double &)'

    This goes on through the entire IOSTREAM file (which I knkow is usually typed in lower-case : ) ) 

    When I dissected the iostream file, the operand >> does NOT show up. What do I do?

    Thanks a bunch!

    #include <iostream>
    using namespace std;
    int main()
    {
    std::cout << "what is your name?" << '\n';
    string name{};

    std::cin >> name;
    std::cout << "what is thy quest, " << name;


    //0000000000000000000000000000000000000
    getchar();
    return 0;
    }

    Monday, May 20, 2019 2:36 PM

All replies

  • >I am a noobi beginner, but have a serious question. I apologize if this is a boring fix. I use Visual Studio, and when I type the following text below and run the program, the following error comes up:

    Your sample code compiles fine for me with the addition of #include <string> with both VS2017 & 2019.

    Dave

    Monday, May 20, 2019 3:42 PM
  • Hi Mgtow01,

    Welcome to MSDN forum.

    Please check this similar issue, if you explicitly use std::string, you need to include string library.

    (Actually the string in your code is std::string).

    >>I use Visual Studio, and when I type the following text below and run the program, the following error comes up:

    When we run the program with start debugging(F5) or start without debugging(Ctrl+F5), vs will build the project before you run the program. Only when the build succeeds and output the xxx.exe file can we run the program. 

    You can notice the prompting message from error list window, every time you find errors and warnings in this window you should check if there is something need to fix or improve:

    Hope all above helps.

    Best Regards

    Lance



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 21, 2019 6:13 AM
  • Hi Mgtow01,

    Sorry to trouble you and just want to confirm that if your issue is solved or not, if not, please feel free to let us know, we will try our best to help you out.

    BTW, if you think the reply is helpful, then could you please mark it as answer, that benefits for other community members who meet the similar issue, thanks in advance.

    If you have any other debug issues, please feel free to let us know. Have a nice day :)

    Best regards,
    Lance


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 27, 2019 6:54 AM