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;
} 2 1679
"Someonekicked" <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(lol.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
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.********@comAcast.net> wrote in message
news:cz0ed.299702$3l3.209104@attbi_s03... "Someonekicked" <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(lol.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
by: Peter Larsen [] |
last post by:
Hi,
Is is possible to programmatically flush all opened files ??
BR
Peter
|
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...
|
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?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
|
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...
|
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |