|
-
July 7th, 2008, 04:07 AM
#1
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
-
July 7th, 2008, 04:59 AM
#2
-
July 7th, 2008, 05:17 AM
#3
Re: std::string IO
Thanks. So is the intellisence independant of the headers we have included?
Rate the posts which you find useful
-
July 7th, 2008, 09:57 AM
#4
Re: std::string IO
 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
-
July 7th, 2008, 10:49 AM
#5
Re: std::string IO
To be fair that's a rather silly error message. "std::string not defined" would have been more intuitive.
-
July 7th, 2008, 11:00 AM
#6
Re: std::string IO
 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
-
July 7th, 2008, 12:55 PM
#7
Re: std::string IO
Ah yes, and such an operator could have been declared using just such a forward declaration, good point.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|