I need to pass string into socket send() function which accepts char * only. So here I am trying to convert it:
void myFunc(std::string str) //Taking string here const is good idea? I saw it on some examples on web
{
char *buf = str.c_str; //taking buf const is good idea?
std::cout << str;
}
int main()
{
const std::string str = "hello world";
myFunc(str);
return 0;
}
Gives error:
test.cpp:6:18: error: cannot convert ‘std::basic_string<_CharT, _Traits, _Alloc>::c_str<char, std::char_traits<char>, std::allocator<char> >’ from type ‘const char* (std::basic_string<char>::)()const’ to type ‘char*’