Insert a number string but only read the first char

I insert “10101” with as_record_set_str(&rec, “test-bin-3”, “10101”),I can get the whole string correctly. but I inserted “10101” like follows,I only got first number char ‘1’ by the function as_record_get_str.

as_record_get_str
as_record rec; char a[5] = {1, 0, 1, 0, 1}; std::stringstream ss; for (int i = 0; i < 5; i++) { ss << a[i]; }

std::string str1 = ss.str();

const char* tmp = str1.c_str();
printf("get length %lu", str1.length());
for (int i = 0; i < str1.length(); i++)
{
    printf("%d ", tmp[i]);
}
printf("\n");

as_record_inita(&rec, binNum);
as_record_set_str(&rec, binName[0].c_str(), str1.c_str());

Try it with char a[5] = {‘1’, ‘0’, ‘1’, ‘0’, ‘1’};

Strings are terminated with a 0 and therefore you only get back the first character.

Cheers, Manuel

It works.Thank you,Manuel.

1 Like