For example
I have char str[1024];
And I will do memset(str,0,1024); later
Is this okay,?
OR
i need to do this:
char* str = new char[1024];
thanks.
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.
As @HostileFork already pointed out, you probably want
std::stringhere. If whatever you’re doing isn’t particularly string-like, then you may wantstd::vector<char> str(1024);instead.Either way, you it’s quite certain you don’t want
new char[1024](a leftover from an early era of C++ that probably wouldn’t be in the language at all if other facilities were present) and probably don’t wantchar str[1024];either, though there’s at least some possibility that this one isn’t an egregious mistake.