printf与cout同时使用的问题

来源:互联网 发布:ip与mac绑定 编辑:程序博客网 时间:2024/06/05 17:20
printf("A\n");  cout<<"B\n";   printf("C\n");

the ouput  is :  
  A  
  C  
  B   
not:  
  A  
  B  
  C 
why? 

answer:    
you   shouldn't   mix   "printf()"   and   "cout"   in   the   same   program   because   C   stdio   and   C++   iostreams   are   completely   independent   and   they   may   have   different   buffering   scheme   and   they   don't   share   the   same   buffer,   so   the   ouput  may   come   out   in   an   order   that   you   are   not   expecting,   that   is   probably   what   happened   in   your   case.
原创粉丝点击