flush the stream

From: Someonekicked (someonekicked_at_comcast.net)
Date: 10/22/04


Date: Fri, 22 Oct 2004 00:50:04 -0400

hi, i cant come to find a solution for a problem in my program, I made an
example of the problem;
in the example i made, the problem is if happy.dat does not exist, so
(!inData) will be true, and "here is the message" is sent to output to
happy.dat, and if u run the program, you will see that "here is the message"
is sent to happy.dat after the program ends, not be4 cout << "check"; i want
that "here is the message" be sent to file be4 seeing "check".
thx in advance for any suggestions , ive been struggling with this for long,
nothing i tried worked.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main() {
 string lol = "happy.dat";
 ifstream inData;
 ofstream outData;
 inData.open(lol.c_str());
 if (!inData)
 {
  outData.open(lol.c_str());
  string message = "here is the message";
   outData << message ;
 }
  cout << "check" << endl;
  int check;
  cin >> check;
 return 0;
}