Comparing strings from arrays does not compute

时间:2019-04-16 22:50:20

标签: c++ arrays string operands

I have an array of strings (a) that correspond to another array of strings (b). The user enters a sequence of either A, U, G, C (UUU, AUG, UGA) and my function finds those in the string the user entered in "a" and replaces them with the corresponding in "b". If what the user entered is not in "a" it should auto default to "ALA" in the string. My for loop to find if it is not in my array gets an error saying no operator(!=) match these opperands. I am using visual studio 2019

#include <iostream>
#include <string>
#include <cctype>

using namespace std;

bool check(string& mRNA);
void replace(string& mRNA, const string& search, const string& replacement);

int main() {

    string mRNA;
    string output;
    string temp;
    string search[10] = { "AUG", "UUC", "AUU", "AUC", "AUA", "GUU", "GUC", "GUA", "GUG", "UUU" };
    string replacement[10] = { "MET", "PHE", "ILE", "ILE", "ILE", "VAL", "VAL", "VAL", "VAL","PHE" };
    int a = 0, g = 0, c = 0, u = 0;

    while (temp != "EXIT") {

        cout << "Please enter an mRNA sequence or type exit to exit." << endl;
        getline(cin, temp);

        for (int i = 0; i < temp.length(); i++) {
            temp[i] = toupper(temp[i]);
        }

        if (temp != "EXIT") {
            mRNA = temp;
            bool good = check(mRNA);
            if (good == false) {
                cout << "The mRNA sequence is invalid. Make sure the sequence was entered correctly" << endl;
            }
        }

        for (int j = 0; j < 10; j++) {
            replace(mRNA, search[j], replacement[j]);
        }

        output = mRNA.substr(0, (mRNA.length() - 3));
        cout << output << endl;
    }
    return 0;
}

void replace(string& mRNA, const string& search, const string& replacement) {
    int pos = 0;
    while ((pos = mRNA.find(search, pos)) != -1) {
        mRNA.replace(pos, 3, replacement);
        pos += 3;
    }
    pos = 0;

    for (int i = 0; i < mRNA.length; i += 4) {
        for (int j = 0; j < search.length(); j++) {
            string temp[1] = { (mRNA.substr(mRNA[i], (mRNA[i] + 2))) };
            if (temp[0] != search[j]) //THE ERROR
        }
    }

}

0 个答案:

没有答案