help with my program vectors and strings

i need to ask the user for some characters that can be infinitely long. then i need to validate that the string only has certain letters. this is like dna sequence. i also have in my class vector<string>DNA.
can someone help me, because i think the problem here is i am using strings which i need but validating only with one letter
1
2
3
4
5
6
7
8
9
10
11
12
13



  string DNA;
     cout<< "Enter a sequence "<<endl;
     getline(cin,DNA);
     
     if(DNA !="a"|| DNA!="c"){
     cout<< "Enter sequence "<<endl;
     getline(cin,DNA);
      }
    DNA.push_back(DNA);
     
See the documentation for find_first_not_of http://www.cplusplus.com/reference/string/string/find_first_not_of/ Obviously, you want your list to contain only "acgt".
But you need to rethink the logic of your program:
- if I enter say "x", on line 6 you assign DNA="x", then since it is not "a" or "c", it will ask again, and I can put "y", so DNA="y" on line 10, and on line 12 DNA="yy"
- if I enter "a", the loop between lines 8 to 11 is not executed, but on line 12 DNA will become "aa"
Topic archived. No new replies allowed.