I am a newbie, I have a problem which trouble me a lot. Please help me out.
I am trying to save char array values in a vector. The size of the vector is the same as the number I push_back. However, all the values in the vector is the last value I push_back.
Here are the code:
vector<char*> qField;
int index = 0;
for (int i =1;i <=q_size-seedLength;i++)
{
index++;
for (int j=0;j<seedLength-1;j++)
{
seed[j] = seed[j+1];
}
seed[seedLength-1] = *q_ptr;
++q_ptr;
seed[seedLength] = '\0';
qField.push_back(seed);
cout << "Insert Seed"<<index<<"\t\t: " <<qField[i]<<"\n";
}
/*
for (int x=0; x<qField.size();x++)
{
cout << " Result Query"<<x<<": " << qField[x]<<"\n";
}
*/
int x = 0;
for(nuc_vector::iterator iter=qField.begin();iter!=qField.end();++iter)
{
cout << x <<"\n";
x++;
cout << "Query " << *iter<<"\n";
}
The strange thing is that the value seems to be stored in the vector right after the push_back. However, when I use another loop to output all the values in the vector qField, all the values are same as the last value pushed back.
Here are part of my results:
Insert Seed7313 : 00133310
Insert Seed7314 : 01333100
Insert Seed7315 : 13331001
Insert Seed7316 : 33310013
Insert Seed7317 : 33100130
Insert Seed7318 : 31001303
Insert Seed7319 : 10013033
0
Query 10013033
1
Query 10013033
2
Query 10013033
3
Query 10013033
4
Query 10013033
5
Query 10013033
6
Query 10013033
Why is that ? Is there any thing wrong.