Comparing String Indexes within a loop.

I am trying to compare corresponding string indexes one at a time within a nested loop.But I keep getting an error and a outcome I know I am not looking for. Need some assistance please?

Here is what I have so far:



*
* File: main.cpp
*
*
*/

#include <iostream>
#include "console.h"
#include "simpio.h"
#include "strlib.h"
#include <string>
#include "lexicon.h"

using namespace std;


int main() {
setConsoleExitProgramOnClose(true);
setConsolePrintExceptions(true);
////////////////////////////////////////////////////////////

// A function that produces all the possible outcomes of only one letter being
// changed
Lexicon english("EnglishWords.dat");
string startWord;
string finishWord;
startWord = getLine("Enter a legal word (must be lowercase): ");
finishWord = getLine("Enter another legal word(must be lowercase): ");

for(int i = 0; i <= startWord.length(); i++) {
string copyWord = startWord;
for(int j = 0; j <= finishWord.length(); j++) {
for(char ch = 'a'; ch <= 'z'; ch++) {
copyWord[i] = ch; // new string from startWord that has one letter change

if (copyWord == startWord) {
continue;
}

if (english.contains(copyWord) && copyWord.at(i) == finishWord.at(j) ) {
cout << copyWord << endl;
}
}
}

}











////////////////////////////////////////////////////////////
getLine("Program finished. Press ENTER to close window(s)");
closeConsoleAndExit();
return 0;
}


Note that one of my startWord string changes by one letter. Trying to return the modified string that has the matching corresponding character with the finishWord string if any.
Topic archived. No new replies allowed.