关于cout的一个疑问

一个人单干 2009-03-31 07:52:02
对于字符类型以外的数组与指针,使用cout输出的是地址,但对于字符数组与字符指针,用cout输出的是字符串。

这是为什么?谁能用cout的函数原型解释一下
...全文
104 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
CJoneL 2009-03-31
  • 打赏
  • 举报
回复
操作符重载问题
ypb362148418 2009-03-31
  • 打赏
  • 举报
回复
看看STL源码里面的ios和iostream的声明与里面的函数重载
leewon1988 2009-03-31
  • 打赏
  • 举报
回复
2L正解
mengde007 2009-03-31
  • 打赏
  • 举报
回复
cout是iostream类的一个对象,它的一个成员operator < <运用了重载机制,因此能承受多种类型
liliangbao 2009-03-31
  • 打赏
  • 举报
回复
cout原型不知,但是我理解是:
cout输出字符数组与字符指针就是输出字符串,可能是和传统的c输出函数统一吧!毕竟C++是C的升级版~
yangqidong 2009-03-31
  • 打赏
  • 举报
回复
cout不是函数,是一个预定义的对象
对输出起作用的实际是 < <符号的重载函数,这个函数接受很多种类型参数,建议看看运算符重载
Paradin 2009-03-31
  • 打赏
  • 举报
回复
因为输出流类重载了operator<<,对各种类型有自定义的操作。

ostream& operator<< (bool& val );
ostream& operator<< (short& val );
ostream& operator<< (unsigned short& val );
ostream& operator<< (int& val );
ostream& operator<< (unsigned int& val );
ostream& operator<< (long& val );
ostream& operator<< (unsigned long& val );
ostream& operator<< (float& val );
ostream& operator<< (double& val );
ostream& operator<< (long double& val );
ostream& operator<< (void*& val );

ostream& operator<< (streambuf* sb );

ostream& operator<< (ostream& ( *pf )(ostream&));
ostream& operator<< (ios& ( *pf )(ios&));
ostream& operator<< (ios_base& ( *pf )(ios_base&));

*** the following functions are not members but GLOBAL functions:

ostream& operator<< (ostream& out, char c );
ostream& operator<< (ostream& out, signed char c );
ostream& operator<< (ostream& out, unsigned char c );

ostream& operator<< (ostream& out, const char* s );
ostream& operator<< (ostream& out, const signed char* s );
ostream& operator<< (ostream& out, const unsigned char* s );
oyljerry 2009-03-31
  • 打赏
  • 举报
回复
cout中输出的时候做了字符串处理

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧