need some help from experienced engineers. I've wrote a function, which gets a string and takes a substring from it. Substrings separated from each other with comma ','. I use assign() function to copy substrings. My code:
void my_function(string devices)
{
    unsigned int last=0;
    unsigned int address;
    printf("whole string: %s\n",devices.c_str());
    for (unsigned int z=0; z<devices.size();z++)
    {
        if(devices[z]==',')     
        {
            zone_name.assign(devices,last,z);
            printf("device:%s\n",zone_name.c_str());
            address=get_kd_address_by_name(zone_name);
            last=z+1;
            if(address>0)
            {   
                //doing stuff
            }
        }
    }
}
My problem: only first iteration works. In terminal i get:
whole string: device1,device2,device3,000001029ADA
device:device1
device:device2,device3
device:device3,000001029ADA
Why assign() takes characters after ','?
 
     
     
    