关于getchar()和cin的疑问
本帖最后由 jiuduying 于 2013-07-24 09:59:32 编辑
为何输入a,#还不停,这是为什么是因为getchar()和cin的区别吗???? getchar,cin,c++ 数据结构
template<class T>
BTNode<T> * BinaryTree<T>::CreatBtree()
{
BTNode<T> * root1=new BTNode<T>;
T ch;
cin>>ch;
getchar();
if(ch=='#') root1=NULL;
else
{
//root=new BTNode<T>;
root1->data=ch;
root1->lchild=CreatBtree();
root1->rchild=CreatBtree();
}
return root1;
}
char ch;
while(scanf("%c", &ch), ch != '#')
{
printf("%c", ch);
}
printf("\nEnd!\n");