读书人

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

发布时间: 2012-02-15 12:09:44 作者: rapoo

菜鸟问题:不能用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;

读书人网 >C++

热点推荐