That Guy
That Guy

Reputation: 154

Error C3867 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str': non-standard syntax; use '&' to create a pointer to member

I have this piece of code, I don't understand why it is displaying this error?

string messege = "aaa";
char tmp[50];
strcpy_s(tmp, messege.length(), messege.c_str);
char* s = NULL;
s = &(tmp[0]);

Can someone help?

Upvotes: 0

Views: 6960

Answers (2)

Shalomi90
Shalomi90

Reputation: 744

c_str is a member function of std::string, so you need to call it with ()

strcpy_s(tmp, messege.length(), messege.c_str());

This will solve your problem.

Upvotes: 0

templatetypedef
templatetypedef

Reputation: 372764

In this line, you've forgotten the parentheses after the call to c_str:

strcpy_s(tmp, messege.length(), messege.c_str);

Adding the missing parentheses should fix this.

That said, it's unusual to want to mix C-style and C++-style strings this way. You may want to think about whether what you're doing is appropriate.

Upvotes: 2

Related Questions