printf与cout同时使用的问题

  printf("A\n");  
  cout<<"B\n";  
  printf("C\n");  
the   ouput      is :  
  A  
  C  
  B   
not:  
  A  
  B  
  C 
why? 

answer:   
   
  1.   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  
   
  2.   try  
   
  cout   <<   "B"   <<   endl;  
   
  or   call    
   
  ios::sync_with_stdio();
posted @ 2009-09-22 23:52  岁月流年  阅读(857)  评论(0编辑  收藏  举报