ostream cout and char *

前端 未结 3 1431
醉话见心
醉话见心 2021-01-27 13:57

I have an array of chars like this one:

char arr[3]=\"hi\";
cout << arr;// this will print out hi

So is the operator<< has an

3条回答
  •  鱼传尺愫
    2021-01-27 14:31

    Exactly in the same way as cout works.

    The array arr decays into pointer type, and there exists an overloaded version of istream as well which takes char* as argument. So arr gets passed to the operator>> as char* after decaying.

提交回复
热议问题