Sorry if this is off-topic.
Just wanted to check .... are std::string's defined
to be null terminated?
I came across a web page that indicated they are,
but you can find lots of misinformation on the web.
std::string's seem to be null terminated with the
Microsoft vc7.1 and vc8 compiler, but I wanted to check if this is generally
true according to the C++ standard.
I'm relatively new to stl and using std::string
.... mostly have used C strings and MFC CStrings (which changed from vc6 to
vc7.1?)
std::string strA = "ABC";
std::string strB =
"DEF";
std::string strC = "GHI";
std::string strD = "JKL";
std::string
strE = "MNO";
// Check if std::string's are null terminated
const char*
pTest = strC.c_str();
for (int i = 0; i < 80; ++i) {
printf("I: %2d ch:%3d %c\n", i, pTest[i],
pTest[i]);
}
std::string testStrings[] = { "abc", "def", "ghi", "jkl"
};
const char* p =
testStrings[1].c_str();
printf("\n********************\n");
for (int i =
0; i < 80; ++i) {
printf("I: %2d ch:%3d %c\n", i,
p[i], p[i]);
}
printf("\n********************\n");
TIA,