Hello ladies and gents,
It's been ages since I posted here, have been doing some coding on and of and I was wondering about the following, beneath is a test I made in trying to use the new operator in combination with a string, first a string literal, second time a string input.
It's working, but, the thing that I'm seeing when debugging this is when I get to the point std::string mName = "John Malkovich";
the value of mName comes up as <bad Ptr>.
Questions:
A) is the way I used the string and new operator correct for this little program?
B) is this <bad Ptr> related to a bad Pointer and what does that mean? Probably not something good?
C) It seems that when I use std::string *pName = new std::string;
, I don't have to determine the sizeof this string? Is this correct? Or is something going wrong which I'm not aware of?
// Testing code.
#include <iostream>
#include <string>
int main()
{
std::string mName = "John Malkovich";
std::string *pName = new std::string;
*pName = mName;
std::cout << "Name is: " << *pName << " !\n";
delete pName;
pName = 0;
std::string secName = "";
getline(std::cin, secName);
pName = new std::string;
*pName = secName;
std::cout << "Second name is: " << *pName << " !\n";
delete pName;
pName = 0;
return 0;
}
Thanks for any help you guys/girls can help.
Edit: oh yes, has the search function been altered on this forum? I seem to remember that you could do a more in depth search for certain subjects you wanted to find out about.