Why do I get garbage value when output character array to console?

后端 未结 2 653
一生所求
一生所求 2020-12-20 06:18

I always get a garbage value like this \'Íýýýý««««««««îþîþ\' at the end when i output my array. What am I doing wrong?

void func()
{
    const int size = 100         


        
2条回答
  •  既然无缘
    2020-12-20 07:08

    Because you don't null terminate your buffer, std::cout.operator<<(char*) will try to find \0 as its terminating character.

    As pointed out in comments, feel free to append that \0 to the end of your buffer :).

提交回复
热议问题