Here i have a string which is split and each line is in a different cell in a vector and i want to retrieve all of the line if the first three letters are .N/ however it seems that i can only retrieve one of the lines which start with .N/ below is the string which i am working with.
std::string message = ".N/1TLIS/PART/123456789I/A/1234RFGH67323\n"
".N/AT0931/2DEC/GVA/Y\n"
".I/KL0967/02APR/AMS/F\n"
".O/123/MARRIOTT/27MAY/084512L//FEDEXVAN45\n";
CODE WHICH I USE AT THE MOMENT
std::vector<std::string> el; //VECTOR
split(el,message,boost::is_any_of("\n"));// the string above is split line for line into vector el
for(int i = 0; i < el.size(); i++)
{
if(el[i].substr(0,3) == ".N/")
{
str = el[i].substr(3);
}
}
cout << str;
However when i print out str i only get “1TLIS/PART/123456789I/A/1234RFGH67323”
and not 1TLIS/PART/123456789I/A/1234RFGH67323 and “AT0931/2DEC/GVA/Y”
Is there a way where i can retrieve all lines starting which a specific character?
You need to append to str, currently you are just replacing, try:
First initialize str with “” before the for loop, then inside the for loop