The constructor of std::string
you used will copy "first=test\0second=jam\0"
until first \0
(C-style string).
To pass all the string use another constructor:
std::string envVars("first=test\0second=jam\0", 22);
^^^^^^^^^^^^^^^^^^^^^^^^ ^
|
22 characters -------+