char * msg = new char[65546];
want to initialize to 0 for all of them. what is the best way to do this in C++?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s known as value-initialisation, and was introduced in C++03. If you happen to find yourself trapped in a previous decade, then you’ll need to use
std::fill()(ormemset()if you want to pretend it’s C).Note that this won’t work for any value other than zero. I think C++0x will offer a way to do that, but I’m a bit behind the times so I can’t comment on that.
UPDATE: it seems my ruminations on the past and future of the language aren’t entirely accurate; see the comments for corrections.