char * msg = new char[65546];
want to initialize to 0 for all of them. what is the best way to do this in C++?
See Question&Answers more detail:oschar * msg = new char[65546];
want to initialize to 0 for all of them. what is the best way to do this in C++?
See Question&Answers more detail:oschar * msg = new char[65546]();
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()
(or memset()
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.