So, I don't know how to explain it, so I wrote out the code, but what I have will only check for the first two letters, so for example, it will catch Dan and Drew, but not Dan and Daniel.
#include <iostream>
#include <string>
usingnamespace std;
int main(){
string names[]={"Drew","Andrew","Dan","Vincent"};
string temp="";
int arrSize = sizeof(names)/sizeof(names[0]);
cout << "The following is a list of names unorganized:\n";
for(int s = 0; s < arrSize; s++)
cout << names[s]<<" ";
for (int x = 0; x < arrSize; x++){
for(int y = 0; y < arrSize-1; y++){
if (names[x].at(0) < names[y].at(0)){
temp = names[x];
names[x] = names[y];
names[y] = temp;
}
elseif (names[x].at(0) == names[y].at(0))
if (names[x].at(1) < names[y].at(1)){
temp = names[x];
names[x] = names[y];
names[y] = temp;
}
}
}
cout << "\n\n\nThe following is a list of names organized:\n";
for(int s = 0; s < arrSize; s++)
cout << names[s]<<" ";
cout << endl << endl;
return 0;
}
Like I said this is just a rough draft, and will only check the first two letters. Once you understand whats going on, it shouldn't be too hard to make it check every letter for a particular string.