I have an array char buffer[]
. What I want to do, is to copy values from buffer
from foundSecondComma+1
to foundSecondComma+1+dataLen
.
Next, I want to creat object Answer a
and pass to constructor few data with part of buffer
.
// here extracted buffer will be stored
char contentData[dataLen];
// extract data from buffer
copy(buffer + foundSecondComma+1, buffer+foundSecondComma+1+dataLen, contentData);
//create new object and push to list
Answer a(dataLen, header, contentData);
answers.push_back(a);
And this is my Answer
class:
Answer::Answer(int dataLen, string header, char* content) {
this->dataLen = dataLen;
this->header = header;
this->content = new char[strlen(content)+1];
strcpy(this->content, content);
}
So for some reason a.content
stores different data than part of buffer
. This simple loop:
for(int i=0; i<v.dataLen; i++)
{
printf("buffer[%d]=%c a.content[%d]=%c\n", i, buffer[foundSecondComma+1+i], i, a.content[i]);
}
Is showing, that values are not the same. Where I make mistake? I am using g++
to compile program.