how to initialize a char array?

前端 未结 8 1848
名媛妹妹
名媛妹妹 2020-12-14 14:39
char * msg = new char[65546];

want to initialize to 0 for all of them. what is the best way to do this in C++?

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-14 15:10

    You can use a for loop. but don't forget the last char must be a null character !

    char * msg = new char[65546];
    for(int i=0;i<65545;i++)
    {
        msg[i]='0';
    }
    msg[65545]='\0';
    

提交回复
热议问题