ostream cout和char * [英] ostream cout and char *

查看:331
本文介绍了ostream cout和char *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的字符数组:

I have an array of chars like this one:

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

so是运算符<有一个重载版本,它接受一个ostream对象和char *。因此 cout<< arr; 第一个arr将衰减到聊天*。然后操作符<<()将打印出char指针指向的东西,直到它找到空字符为止。

So is the operator<< has an overloaded version that takes an ostream object and char *. so cout<<arr; first arr will decays to a chat * . and then operator<<() will print out what the char pointer is pointing to until it find a null-character ?

推荐答案

您的 ostream istream > operator operator>> 重载以获取 char * 并且阵列衰减到指向第一元素的指针。所以,是的,它做你所说的。

Your ostream and istream do have operator<< and operator>> overloaded to take a char*, and arrays decay into pointers to the first element. So, yes it does what you say it does.

这篇关于ostream cout和char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆