Jump to content
  • Advertisement
Sign in to follow this  
eedok

wtf visual studio

This topic is 4439 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

for some reason this won't compile
#include <iostream>
using namespace std;

int main()
{
	int t=0;
	string str = "lol";
	while (t==0)
	{
		cout<<str<<endl;
		cin >> t;
	}
}




when I hit the almighty compile button I'm getting this: c:\Documents and Settings\cody\Desktop\test\hello.cpp(10): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) umm well I can't find any problems in my code so maybe someone else could help me? EDIT: Forgot to add I'm using VS.NET 2003 standard oddly enough this works:
#include <iostream>
using namespace std;

int main()
{
	int t=0;
	string str = "lol";
	while (t==0)
	{
		cout<<str.c_str()<<endl;
		cin >> t;
	}
}


Share this post


Link to post
Share on other sites
Advertisement
I'm a n00b, but it seems to me that you are mixing c and c++ functions. Try the c++ string printer istead of cout.

or use char[4] = "lol\0" instead of string.

Share this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton
#include <string> [wink]

thanks that fixes it, odd how the 2nd example works though

Share this post


Link to post
Share on other sites
That's because iostream declares the operator<<(std::ostream, const char *) overload, but does not declare the operator<<(std::ostream, const std::string &) overload. To get that, you need to include <string>.

Share this post


Link to post
Share on other sites
Quote:
Original post by eedok
thanks that fixes it, odd how the 2nd example works though

Actually, I think it's odd that it works at all without the <string> include. Otherwise, the second version works because cout expects a char array, which is what string::c_str() returns.

Share this post


Link to post
Share on other sites
here's another strange encounter this line of code gives me a couple errors as well:

std::transform(myString.begin(), myString.end(), myString.begin(), std::toupper);


'toupper' : is not a member of 'std'
'transform' : is not a member of 'std'

oddly enough they came up in the autocomplete, so I'm pretty sure they're a member of std.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
Did you include <algorithm> and <cctype>?


nope, is there a site saying what you have to include to make things work for STL stuff, as it's looking like I'm having some issues with it.

Share this post


Link to post
Share on other sites
Quote:
Original post by eedok
is there a site saying what you have to include to make things work for STL stuff, as it's looking like I'm having some issues with it.


MSDN has lots of information on the STL, such as necessary include files.

Also, just a general tip. Problems like these are almost never the compiler or the IDE's fault, which is to say they are the programmers. Making a topic with a title like "wtf visual studio" leads me to believe, at first glance, that you have a problem for which you blame your IDE. IMO one of the biggest mistakes a beginner can make is to blame his compiler for his own mistakes (not to imply that you do this, just a general observation as I have dealt with people who do this far too often). I'm not trying to be the least bit malicious, I just suggest to you may find it helpfull in the future to approach problems from the perspective of "what did I do wrong?" rather than "why is my IDE broken?".

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!