This is in reference to the following answer by Synxis.
Suppose, I have to print all substrings of the string "cbaa". To do this, I have to invoke the method like this:
findAllSubstrings2("cbaa");
If I take a string from user, and do the following:
string s;
cin>>s;
findAllSubstrings2(s);
it gives the following error:
[Error] cannot convert 'std::string {aka std::basic_string<char>}' to 'const char*' for argument '1' to 'void findAllSubstrings2(const char*)'
Why does this happen?
As the error message says the parameter of function
findAllSubstrings2
is declared as having typeconst char *
while you are trying to pass an argument of typestd::string
You should use member function
c_str
ordata
(starting from C++ 11) of classstd::string
. For example