首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

初学者有关问题:不能用cin给指针变量赋值?

2012-02-15 
菜鸟问题:不能用cin给指针变量赋值??int*pcin p//编译的时候没有问题,但是一运行就出错这是为什么啊?[

菜鸟问题:不能用cin给指针变量赋值??
int   *p;
cin   > >   p;   //编译的时候没有问题,但是一运行就出错

这是为什么啊?

[解决办法]
编译也不过的:
error C2679: binary '> > ' : no operator defined which takes a right-hand operand of type 'int * ' (or there is no acceptable conversion)
Error executing cl.exe.
[解决办法]
楼主是不是想这样?
int *p = new(int);
cin > > *p;
.............
delete p;

热点排行