D
David Resnick
Is the assignment of a substr of the string 'a' to 'a' in the
code below OK?
#include <string>
#include <iostream>
int main(void)
{
std::string a = "hello";
std::cout << a << std::endl;
a = a.substr(0,2);
std::cout << a << std::endl;
return 0;
}
I saw no restrictions on operator= in my STL reference (Josuttis).
But this makes me slightly nervous. I've programmed more in C
than C++, and this feels like it could be rather like an overlapping
strcpy (or multiple modifications of an object without intervening
sequence point). This code works, and valgrind doesn't complain, but
I'd
still like to know if it is guaranteed to be correct usage.
Thanks,
-David
code below OK?
#include <string>
#include <iostream>
int main(void)
{
std::string a = "hello";
std::cout << a << std::endl;
a = a.substr(0,2);
std::cout << a << std::endl;
return 0;
}
I saw no restrictions on operator= in my STL reference (Josuttis).
But this makes me slightly nervous. I've programmed more in C
than C++, and this feels like it could be rather like an overlapping
strcpy (or multiple modifications of an object without intervening
sequence point). This code works, and valgrind doesn't complain, but
I'd
still like to know if it is guaranteed to be correct usage.
Thanks,
-David