C++为什么cin可以给数组整体赋值?
chara[]={"sfg"};cin>>a;为什么这样是可行的?a不是一个用来表示数组内存地址的常量吗?就像不可以chara[]={"sfg"};a="fdd";为什么...
char a[]={"sfg"};
cin>>a;
为什么这样是可行的? a不是一个用来表示数组内存地址的常量吗?
就像不可以
char a[]={"sfg"};
a="fdd";
为什么? 展开
cin>>a;
为什么这样是可行的? a不是一个用来表示数组内存地址的常量吗?
就像不可以
char a[]={"sfg"};
a="fdd";
为什么? 展开
展开全部
刚看到你这个问题。然后我去查了c++ documentation。他是这样解释的
character sequence (2)
istream& operator>> (istream& is, char* s);
istream& operator>> (istream& is, signed char* s);
istream& operator>> (istream& is, unsigned char* s);
(2) character sequence
Extracts characters from is and stores them in s as a c-string, stopping as soon as either a whitespace character is encountered or (width()-1) characters have been extracted (if width is not zero).
A null character (charT()) is automatically appended to the written sequence.
The function then resets width to zero.
意思就是>>运算符本来就被重载了可以接受char*为参数,所以就可以写成cin >> a咯,哈哈。
character sequence (2)
istream& operator>> (istream& is, char* s);
istream& operator>> (istream& is, signed char* s);
istream& operator>> (istream& is, unsigned char* s);
(2) character sequence
Extracts characters from is and stores them in s as a c-string, stopping as soon as either a whitespace character is encountered or (width()-1) characters have been extracted (if width is not zero).
A null character (charT()) is automatically appended to the written sequence.
The function then resets width to zero.
意思就是>>运算符本来就被重载了可以接受char*为参数,所以就可以写成cin >> a咯,哈哈。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
a是表示这一组数组的首地址 而cin>>a成立的原因是iostream头文件中把>>运算符重载了
追问
具体是怎么做的呢
追答
= =这牵扯到一个非常大的重载类函数 你知道去看百科吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-09-08
展开全部
哪来的cin,哪来的赋值。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询