Reputation: 154
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
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
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