Thanks Peter, what you say makes sense, I changed it to < PosPrimaryEndMarker and initialised the PosSecocondaryStartMarker before the loop using
PosSecondaryStartMarker = XmlFileAsString.find(SecondaryStartMarker, PosPrimaryStartMarker);
So now it should get the position.
Because the XmlFileAsString being searched has multiple groups of data, and I need to keep the groups seperate (they will end up in arrays evetually) I can't use npos again for the inner markers. The best analogy I can think of would be that the file is like a stack of 100's of sandwiches and those sandwiches contain poptarts stacked inside the sandwiches.
The primary markers represent the slices of bread, the secondary markers represent the poptart outer layers, and the jam filling is the data. I want to take the jam out of all the poptarts on a per sandwich basis so I can have seperate groups. My understanding is npos in the second while will just plough through the sandwich stack in one go until it gets to the end.
I tried my modified code and unforunately it just seems to get stuck the same.
I just get..
PrimaryStartMarker: 86763
PrimaryEndMarker: 87173
I don't even get the cout that says "Secondary Marker Loop" which is bizzare, I just don't understand. This is the modified code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
while ((PosPrimaryStartMarker = XmlFileAsString.find(PrimaryStartMarker, PosPrimaryStartMarker)) != std::string::npos)
{
std::cout << "PrimaryStartMarker: "<<PosPrimaryStartMarker << std::endl;
PosPrimaryEndMarker = XmlFileAsString.find(PrimaryEndMarker, PosPrimaryStartMarker);
std::cout << "PrimaryEndMarker: " << PosPrimaryEndMarker << std::endl;
PosSecondaryStartMarker = XmlFileAsString.find(SecondaryStartMarker, PosPrimaryStartMarker);
while ((PosSecondaryStartMarker = XmlFileAsString.find(SecondaryStartMarker, PosSecondaryStartMarker)) < PosPrimaryEndMarker);
{
std::cout << "Secondary Marker Loop: " << PosSecondaryStartMarker;
//get each data ref
PosSecondaryEndMarker = XmlFileAsString.find(SecondaryEndMarker, PosSecondaryStartMarker);
std::string DataRef = XmlFileAsString.substr(PosSecondaryStartMarker, PosSecondaryEndMarker - PosSecondaryStartMarker);
std::cout << "DataRef: " << DataRef;
PosSecondaryStartMarker = (PosSecondaryEndMarker + SecondaryStartMarker.length());
}
//std::string DataRef = XmlFileAsString.substr(PosPrimaryStartMarker, PosPrimaryEndMarker - PosPrimaryStartMarker);
//std::cout << "DataRef: " << DataRef << std::endl;
PosPrimaryStartMarker = (PosPrimaryEndMarker + PrimaryEndMarker.length());
//PosPrimaryMarker = (PosPrimaryMarker + PrimaryMarker.length());
}
|