Sign in to follow this  

about std::string

Recommended Posts

I have two little questions about std::string:
#include <iostream>

void func(const std::string& s)
	//std::cout << s << std::endl;  /* Q1 */
	std::cout << s.c_str() << std::endl;

void func(const char *s)
	std::cout << s << std::endl;

int main(int argc, char* argv[])
	func("hello");  /* Q2 */
	return 0;

Q1. why this error message ? a.cpp(9) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion Q2. func("hello") calls to func(char *) if there are the two version, one string and other char*, why? and how to override this ? thanks

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