News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

C++ TIps: IO - stdio and iostream have independent buffers

Started by ben2ong2, October 06, 2006, 11:12:08 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ben2ong2

[ Adapted from "C++ Gotchas", tutorial notes by Tom Cargill,
  page 56. ]

#include <stdio.h>
#include <iostream.h>

void m1 ()
{
   printf ("quickly reaching boiling point\n");
}

void m2 ()
{
   cout << "utter chaos" << endl;
}

int main ()
{
   m1();
   m2();
   return 0;
}

This program might output:

quickly reaching butter chaos
oiling point

It is usually better to use stdio or iostreams. If you want
both, you can explicitly flush before switching. For another
related tip on this see the file buf_io.

(TableOfContents and tips are in /home/sim/c++tips)
You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login