cout.tie(&cin)为什么报错?

看C++primer,cin可以关联cout,反过来cout不能关联cin吗?

是否tie函数不能逆用,只能输入关联输出,cout也是定义了tie函数的,目的只是为了返回关联的istream吗

        cout.tie(&cin);   //error: no matching function for 
                            //call to 'std::basic_ostream<char>::tie(std::istream*)'
       // cout.tie();
        cin.tie(&cout);
        
阅读 3k
1 个回答

刚刚看了一眼cplusplus.com
发现tie函数是在basic_ios类里
原型是这样的:

basic_ostream<char_type, traits_type> tie(basic_ostream<char_type, traits_type> tiestr);

也就是说,tie函数只能这么用:
cin.tie(&cout);//legal
cout.tie(&cout);//legal
cout.tie(&cin);//compile error

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题