Ryan's District Boards

Computer, programming, and webmaster help , support , tips and tricks => Tutorials Zone! => Internet webmaster computer programming technology tips and tricks => C++ / C / C# ....Tutorials => Topic started by: ben2ong2 on October 06, 2006, 11:12:08 PM

Title: C++ TIps: IO - stdio and iostream have independent buffers
Post by: ben2ong2 on October 06, 2006, 11:12:08 PM
[ 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)