Jump to content
  • Advertisement
Sign in to follow this  
derek7

why not work

This topic is 4801 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#include <iostream> main(){ std::string source = "Hello"; std::cout << source <<std::endl; } error:C2679

Share this post


Link to post
Share on other sites
Advertisement
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
int main(void) {
// ...blahblah
return 0;
}

C++ doesn't like the old C-style "main() {}" with no return value.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!