the compare() function is not what you need. It only tells you whether one string is the same as the other. you need to check the two strings one character at a time and create a third string that contains the characters which are in both strings. For example, the first two strings have the letters 'A' and 'M' in both strings, so a third string will contain "AM".
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
you can use a loop. Something like below. The find() method will search one string for an instance of another string and return the position where its at.
string str1 = "ABC";
string str2 = "BCD";
string result;
for(int i = 0; i < str2.length(); ++)
{
if( str1.find( str2[i] ) != string::npos )
result += str2[i];
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
nicko, thats my post. thanks anywayy
Your solution was nearly identicale to mine except your made a check to insure duplicates are not inserted into the new string. If you already knew the solution why did you post the question in this thread?:eek: :?: :rolleyes:
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
now you are asking a completly different question. vectors of what? strings? do you want to create a vector that is a union of two other vectors, where each string in the new vector is the union of the corresponding strings in two or more other vectors? The algorithm would be almost identical to what has already been posted.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343