Sign in to follow this  
derek7

why not work

Recommended Posts

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;

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by CTar
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;


Yes it does.

Share this post


Link to post
Share on other sites
Quote:
Original post by CTar
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;

It accepts std::strings. There's no need to use c_str().

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
The return value is not required. The standard declares that a main function which terminates without a return statement implicitly returns zero.

Enigma

Share this post


Link to post
Share on other sites
Quote:
Original post by Enigma
The return value is not required. The standard declares that a main function which terminates without a return statement implicitly returns zero.

I'm not sure the standard actually says that. Perhaps it does for compatability with very old versions of C. Even so, I'd suggest you should just return anyway as a matter of course.

Share this post


Link to post
Share on other sites
Quote:
Original post by Andrew Russell
I'm not sure the standard actually says that. Perhaps it does for compatability with very old versions of C. Even so, I'd suggest you should just return anyway as a matter of course.

Well, it's definitely in the final draft. I don't own a copy of the final standard, but the final draft states in section 3.6.1, paragraph 5:
Quote:
A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing

return 0;

But your suggestion is, naturally, good advice.

Enigma

Share this post


Link to post
Share on other sites
Quote:
Original post by Enigma
Quote:
Original post by Andrew Russell
I'm not sure the standard actually says that. Perhaps it does for compatability with very old versions of C. Even so, I'd suggest you should just return anyway as a matter of course.

Well, it's definitely in the final draft. I don't own a copy of the final standard, but the final draft states in section 3.6.1, paragraph 5:
Quote:
A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing

return 0;

But your suggestion is, naturally, good advice.

Enigma


Hah! I stand corrected! I could have SWORN, though. I'm pretty sure I've used a version of g++ that complained about it, a few years ago.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this