Then, I delete the pointer to get the second element in the line where I put it in the pointer.
My function compiles, but, when I run it, it gives me a segmentation fault message.
Would like to know what I am missing here.
Thank you.
> I am using string pointer to enable me to get an element from the line then
> push it into the first vector
wrong, ¿why can't you do that with a string? http://www.cplusplus.com/forum/general/138037/
note that you have the new inside the loop, so it creates a new one every iteration. Potentially you may have `line.size()' allocations but just one deallocation
> strPtr[z] = line[x];
now you are treating it as if it were a dynamic array. That tries to access the string in the position `z', not the character.
If instead it were string strPtr;, the string would be empty, and try to access the element `z' would also be wrong.
1 2 3 4 5 6 7 8 9 10 11 12 13
string aux; //outside the loop
aux.reserve(line.size()); //at most all characters may be copied
for(int x = 0; x < line.size(); x++) { //limit the scope of your variables
if(line[x] != ',') {//copying
aux.push_back(line[x]);
} else //inserting to the vector
{
inner.push_back(aux);
aux.clear();
}
}
outer.push_back(inner);
However the `aux' string is not even needed. You may use `.substr()' to select the segment to copy, and `.find()' to get the position of the `,'
Apparently, you have an advanced level of C++ than my level.
But, I see that you are treating : string aux the same as vector?
I appreciate your feedback.