I don't know a way to enter string into a vector.
For example, there is string s = "augcuuaucaca" and I want to separate the string s into groups of 3 characters such as "aug", "cuu", "auc", "aca" and each group of characters would be string type.
After that, I would store "aug" into vector[0], "cuu" into vector[1], etc...
So each element of vector would have a 3 character group.

I tried many different ways but I can't seem to find the solution. I need help how to solve this.
Below are some of my attemps to solve this the problem.

cout << s << endl;	
for (int i=0; i < s.length() - 2; i+3)
{
	char temp[3];
	cin.get (temp, 3);
	codons.push_back (temp);
	cout << "The codons: " << codons[i] << endl;
}
vector<char> codons;
	
for (int i=0; i < dnaStrand.length() - 2; i+3)
{
	char temp[] = { dnaStrand[i], dnaStrand[i+1], dnaStrand[i+2] };
	codons.push_back (temp);
}
vector<string> codons;
	
for (int i=0; i < dnaStrand.length() - 2; i+3)
{
	char temp[] = { dnaStrand[i], dnaStrand[i+1], dnaStrand[i+2] };
	codons.push_back (temp);
}
string s("augcuuaucaca");
string temp;
int size = s.size();
int pos = 0;
vector<string> list;

do{
     try
     {
          temp = s.substr(pos, 3);
          list.push_back(temp);
          pos += 3;
     }
     catch(out_of_range)
     {
          break;
     }
}while(pos != size);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.