0
I try to sort strings alphabetically for only the first 5 letters of the alphabet (a,b,c,d,e) and show to me this error
76|error: no matching function for call to 'std::__cxx11::basic_string<char>::copy(std::__cxx11::string&)'| https://code.sololearn.com/cAN3MKKIOlPC/?ref=app
2 Antworten
+ 1
Hi Mohammed Aldhanuna , issue is in usage of copy function... Why you preferred to use the same when there are two string with you... You can simply use = something like below :
string s1 = "Test";
string s2;
s2 = s1;
However , regarding copy function you have used it incorrectly so getting error. It should be used to string object which is having value or you can say from which you want to copy.. some dummy code for copy function example :
string s = "Hello";
char* t = new char[7];
s.copy(t,2,1);
cout << t;
Here, 2 means 2 char to be copied and 1 is indication that start from first position... So above would print el.. additionally, as we allocated memory using new , it should be de allocated as well
+ 1
Mohammed Aldhanuna just as Ketan Lalcheta has said,you've used the member function copy in the wrong way.I don't see how you could use it to implement a sorting algorithm.
Nonetheless,I would advise you to use std::sort found in <algorithm> like this:
std::sort(name,name+SIZE);
Instead of writing your own