why not work
#include <iostream>
main(){
std::string source = "Hello";
std::cout << source <<std::endl;
}
error:C2679
Quote:Original post by Ra
You need #include <string> to use std::string.
And std::cout doesn't take std::strings. You have to change the cout line to this:
std::cout << source.c_str() <<std::endl;
According to MSDN - assuming MSVC - error:C2679 means:
"binary 'operator' : no operator found which takes a right-hand operand of type 'type' (or there is no acceptable conversion)"
This code has two binary operators: = and << std::string overloads both of them so as far as I know, this code should work. You're not using MSVC 5.0 or anything are you?
This is not you're problem but you should declare int main( ) and have it return 0 at the end.
"binary 'operator' : no operator found which takes a right-hand operand of type 'type' (or there is no acceptable conversion)"
This code has two binary operators: = and << std::string overloads both of them so as far as I know, this code should work. You're not using MSVC 5.0 or anything are you?
This is not you're problem but you should declare int main( ) and have it return 0 at the end.
Quote:Original post by CTarQuote:Original post by Ra
You need #include <string> to use std::string.
And std::cout doesn't take std::strings. You have to change the cout line to this:
std::cout << source.c_str() <<std::endl;
Yes it does.
Quote:Original post by CTarQuote:Original post by Ra
You need #include <string> to use std::string.
And std::cout doesn't take std::strings. You have to change the cout line to this:
std::cout << source.c_str() <<std::endl;
It accepts std::strings. There's no need to use c_str().
Sorry, I was almost sure I have had a problem before with using std::strings and std::cout together, but then it must have been something else, or my memory is just bad.
int main(void) {
// ...blahblah
return 0;
}
C++ doesn't like the old C-style "main() {}" with no return value.
// ...blahblah
return 0;
}
C++ doesn't like the old C-style "main() {}" with no return value.
The return value is not required. The standard declares that a main function which terminates without a return statement implicitly returns zero.
Enigma
Enigma
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement