I need help to understand putting all entries into first string. Then I need to search the first string and if there are duplicated letters, I put the duplicated letters into second string.
I have read the tutorials. It should be simple? But I can not code it. Here is my unworking code.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string first = "";
string second = "";
string letter = "";
cout << "Enter a lowercase letter: ";
cin >> letter;
while (letter != "ZZZ")
{
first = first + letter; //put all entries in first string
cout << "string first: " << first << endl << endl; //******test print*******
// search first string for duplicated letters
for (int x = 0; x < first.length(); x++)
{
if (first.substr(x, first.length() - 1) == letter)
{
second = second + letter; //put duplicated letters in second string
}
} //end for
cout << "string second: " << second << endl << endl; //*******test print*******
cout << "Enter a lowercase letter: ";
cin >> letter;
} //end while
system("pause");
return 0;
}