CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: std::string IO

  1. #1
    Join Date
    Jan 2008
    Location
    India
    Posts
    408

    std::string IO

    Code:
    #include<iostream>
    int main()
    {
     std::string szName;
     std::cin >> szName;
     std::cout << szName << std::endl;
     return 0;
    }
    This code, while compilation gives the following error.
    --------------------Configuration: BasicString - Win32 Debug--------------------
    Compiling...
    Test.cpp
    d:\bharani\programming\c++\basicstring\test.cpp(6) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no ac
    ceptable conversion)
    d:\bharani\programming\c++\basicstring\test.cpp(7) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no ac
    ceptable conversion)
    Error executing cl.exe.
    Test.obj - 2 error(s), 0 warning(s)
    What may be the problem?

    Thanks.
    Rate the posts which you find useful

  2. #2
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725

    Re: std::string IO

    Yiu need to:

    Code:
    #include <string>

  3. #3
    Join Date
    Jan 2008
    Location
    India
    Posts
    408

    Re: std::string IO

    Thanks. So is the intellisence independant of the headers we have included?
    Rate the posts which you find useful

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: std::string IO

    Quote Originally Posted by ajbharani
    Thanks. So is the intellisence independant of the headers we have included?
    Intellisense is not C++.

    If you're going to use std::string, then you must include the <string> header. Don't solely rely on third-party tools such as Intellisense to determine proper C++ coding.

    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: std::string IO

    To be fair that's a rather silly error message. "std::string not defined" would have been more intuitive.
    My hobby projects:
    www.rclsoftware.org.uk

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: std::string IO

    Quote Originally Posted by Zaccheus
    To be fair that's a rather silly error message. "std::string not defined" would have been more intuitive.
    I think that std::string is forward declared within the stream headers, so it is difficult for the compiler to emit such an error.

    Regards,

    Paul McKenzie

  7. #7
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Thumbs up Re: std::string IO

    Ah yes, and such an operator could have been declared using just such a forward declaration, good point.
    My hobby projects:
    www.rclsoftware.org.uk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured