473,748 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

flush the stream

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(lo l.c_str());
string message = "here is the message";
outData << message ;
}
cout << "check" << endl;
int check;
cin >> check;
return 0;
}
Jul 22 '05 #1
2 1687
"Someonekic ked" <so***********@ comcast.net> wrote...
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(lo l.c_str());
string message = "here is the message";
outData << message ;
Try adding

outData << flush;
outData.close() ;

although the effect is probably still platform-specific.
}
cout << "check" << endl;
int check;
cin >> check;
return 0;
}


V
Jul 22 '05 #2
hey, thank YOU, it works. i tried fflush b4, it did not work, maybe becuz i
dont know how to use it, and for sure i tried close() alone, it did not work
either, anyway, thx a lot !
"Victor Bazarov" <v.********@com Acast.net> wrote in message
news:cz0ed.2997 02$3l3.209104@a ttbi_s03...
"Someonekic ked" <so***********@ comcast.net> wrote...
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(lo l.c_str());
string message = "here is the message";
outData << message ;


Try adding

outData << flush;
outData.close() ;

although the effect is probably still platform-specific.
}
cout << "check" << endl;
int check;
cin >> check;
return 0;
}


V

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
717
by: Daniel | last post by:
System.IO.StreamWriter Close or Flush method to shut down the computer in such a way that just part of the file is written? or an empty file is written? Also if the Close or Flush is to a streamwriter writing to a network share, is it possible for the network to go down in such a way that the tartet file is only partialy written? or are there some kind of check sums to prevent this.
30
45804
by: Jonathan Neill | last post by:
I'm aware that there is no ANSI (or POSIX, or any standard, to my knowledge) way of flushing stdin or any other application-level input buffer, but if anyone knows a hack or a non-portable way to do this, no matter how obscure or arcane, I'd appreciate it.
4
15062
by: Johnathan Doe | last post by:
I'm trying to find a way to reliably peek at stdin, and if anything's waiting, flush stdin so that it clears the stream ready to wait for a character. The problem I have is that in an application, if I call say scanf() to get some input, occasionally the newline is still left hanging around in the buffer. If there's any junk left over in stdin after getting input I'd like to clear it out. And then when going to read input again later,...
5
6545
by: Simon Johnson | last post by:
I have a TCP Client class for which I use StreamWriter to send data across the network. The question I have is does the StreamWriter.Flush() method block code execution until all the data has been sent to the client? Simon.
3
22469
by: guy | last post by:
I can't find this in the documentation so I'm asking it here: I assume that if I call Close() on a Stream based class that Flush() does not need to be called before as it is implicitly called by Close()? Thanks
1
5485
by: nitroamos | last post by:
i'm working on improving the IO for the software project i'm working on to do two extra things. first, i'm going to add HDF5 functionality, and second, add the ability to write binary output. the software is computational science where a lot of stuff is going to be calculated and written to a file. e.g. could be up to gigabytes of data. my question has to do with the latter -- and how often i need to call "flush" on the stream. what I...
6
17232
by: tegdim | last post by:
Hello, I'm trying to send a string to a subprocesses' output stream in my java program. I'm writing the data to the stream and then trying to flush the stream. This, however , isn't actually sending anything to the subprocess (a python program) and the data only actually gets sent to the outputstream when I close the stream. I'm wanting to keep sending data to the subprocess so the writing and flushing is in a loop, but because I have to...
10
3594
by: Peter Larsen [] | last post by:
Hi, Is is possible to programmatically flush all opened files ?? BR Peter
5
5731
by: Spam Catcher | last post by:
Hi all, I'm accessing a synchronized Streamwriter from potentially several threads to do some logging. Is the Flush command threadsafe too? Should I single thread the Flush command or will the Synchronized streamwriter handle that for me? Thanks!
1
2211
MrPickle
by: MrPickle | last post by:
Does a stream flush itself when it is destroyed? If so, is it best just to let the stream flush itself and only flush it when you want it's buffer synchronizing?
0
9561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9332
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8252
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.