problem with validate

i need to validate that user can only put a c g t but does not work properly
can anyone help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

vector<string> DNA;

 void a:: input(){
     
      string DNA ;
    
         cout<<"Enter DNA Sequence" <<endl;
         cin >> DNA;
	
        DNA.push_back(DNA);//
	for (int i=0;i<DNA.size();i++){
	  DNA=DNA[i];
	   if (DNA[i] != 'A' && DNA[i] != 'a' && DNA[i] != 'u' && DNA[i] != 'U'
	       && DNA[i] != 'C' && DNA[i] != 'c' && DNA[i] != 'G' && DNA[i] != 'g'){
		cout<<"has to be a,c,g,t" <<endl;
         	cin >> DNA;
	   }
	    
	   
	}
	  
}
I already showed you a method.

1
2
3
4
5
6
const char valid_letters[] = "AaUuCcGg";

if ( DNA.find_first_not_of( valid_letters ) != std::string::npos )
{
   std::cout << "Has to be \'" << valid_letters << "\'\n";
}


By the way this statement

DNA.push_back(DNA);//

shall not be compiled.
Topic archived. No new replies allowed.