c++ - CPP string constructor find and append null characters -
in c++ strings
copied until null
character received while feeding in sequence of characters. if supply number of characters read, copy past null
character? have situation may receive message has null character in middle , still useful information after it. same question applies append.
similarly find()
, stop searching if hits null
character?
you should able construct string containing '\0'
character:
const char a[] = "hello\0world"; std::string s(a, sizeof(a)); std::cout << "a = \"" << << "\"\n"; std::cout << "s = \"" << s << "\"\n"; std::cout << "sizeof(a) = " << sizeof(a) << '\n'; std::cout << "strlen(a) = " << std::strlen(a) << '\n'; std::cout << "s.length() = " << s.length() << '\n';
the above snippet print
= "hello" s = "helloworld" sizeof(a) = 12 strlen(a) = 5 s.length() = 12
Comments
Post a Comment