|

楼主 |
发表于 2004-10-18 13:19:37
|
显示全部楼层
编译器中说的:
[root@localhost c01]# g++ p6_c.cpp -o p6_c
p6_c.cpp: In function `int main()':
p6_c.cpp:7: error: no match for 'operator>>' in 'std::cin >> i'
操作符>>中规定cin>>i是非法的,
而cin>>char是合法的,
这么理解对吗?
因为
- char *name=new char[8];
- cout<<"please input your name:";
- cin>>name;
- cout<<"hello,"<<name<<endl;
复制代码
是正确的,而
- int *name=new int[8];
- cout<<"please input your name:";
- cin>>name;
- cout<<"hello,"<<name<<endl;
复制代码
是错误的。
下面的是正确的:
- int *name=new int[8];
- cout<<"please input your name:";
- cin>>name[8];
- cout<<"hello,"<<name[8]<<endl;
复制代码
那么为什么编译器只允许char,
而不允许int,允许int[]?
谢谢。 |
|