G
Gaijinco
I made this function which given two strings c1 and c2 test if with the
letters of both you can exactly form the string c3, so for exaple c1 =
"evol" c2= "ution" and c3 = "evolution" will yield true.
The function looks like this:
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
bool areSubComp(string c1, string c2, string c3)
{
c1+=c2;
sort(c1.begin(),c1.end());
sort(c3.begin(),c3.end());
if(c1==c3)
return true;
else
return false;
}
int main()
{
cout << areSubComp("eouio","vltn","evolution"); // line 19
return 0;
}
I was trying to pass the last two arguments as reference to avoid the
copy of both strings using:
bool areSubComp(string c1, string& c2, string& c3)
but the compiler gives me this error:
line 19: cannot convert parameter 2 from 'char [5]' to 'class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > &'
What's wrong and how can I accomplish what I wanted to?
Thanks.
letters of both you can exactly form the string c3, so for exaple c1 =
"evol" c2= "ution" and c3 = "evolution" will yield true.
The function looks like this:
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
bool areSubComp(string c1, string c2, string c3)
{
c1+=c2;
sort(c1.begin(),c1.end());
sort(c3.begin(),c3.end());
if(c1==c3)
return true;
else
return false;
}
int main()
{
cout << areSubComp("eouio","vltn","evolution"); // line 19
return 0;
}
I was trying to pass the last two arguments as reference to avoid the
copy of both strings using:
bool areSubComp(string c1, string& c2, string& c3)
but the compiler gives me this error:
line 19: cannot convert parameter 2 from 'char [5]' to 'class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > &'
What's wrong and how can I accomplish what I wanted to?
Thanks.