flush

Flushing stdin after every input - which approach is not buggy?

霸气de小男生 提交于 2019-11-27 23:14:08
After Mark Lakata pointed out that the garbage isn't properly defined in my question I came up with this. I'll keep this updated to avoid confusions. I am trying to get a function that I can call before a prompt for user input like printf("Enter your choice:); followed a scanf and be sure that only the things entered after the prompt would be scanned in by scanf as valid input. As far as I can understand the function that is needed is something that flushes standard input completely. That is what I want. So for the purpose of this function the "garbage" is everything in user input i.e. the

python print function in real time

允我心安 提交于 2019-11-27 22:58:06
I recently switched OS and am using a newer Python (2.7). On my old system, I used to be able to print instantaneously. For instance, suppose I had a computationally intense for loop: for i in range(10): huge calculation print i then as the code completed each iteration, it would print i However, on my current system, python seems to cache the stdout so that the terminal is blank for several minutes, after which it prints: 1 2 3 in short succession. Then, after a few more minutes, it prints: 4 5 6 and so on. How can I make python print as soon as it reaches the print statement? Try to call

Python3 sleep() problem

北慕城南 提交于 2019-11-27 22:17:06
I was writing a simple program on Python 3.1 and I stumbled upon this: If I run this on the IDLE it works as intended - prints "Initializing." and then adds two dots, one after each second, and waits for input. from time import sleep def initialize(): print('Initializing.', end='') sleep(1) print(" .", end='') sleep(1) print(" .", end='') input() initialize() The problem is that when I double-click the .py to execute the file, it runs on python.exe instead of pythonw.exe, and strange things happen: it joins all the sleep() times i.e. makes me wait for 2 seconds, and then prints the whole

Understanding Streams and their lifetime (Flush, Dispose, Close)

ⅰ亾dé卋堺 提交于 2019-11-27 20:30:17
问题 Note: I've read the following two questions already: Can you explain the concept of streams? C# using streams I'm coding in C# In almost all code samples that use streams, .Dispose(), .Flush(), .Close() are almost always called. In the concept of a stream, what does accomplish? If I don't dispose a stream that I stored in a variable, is my application leaking somewhere? Why do I need to call any of these functions? I've seen code samples that don't do this and still get the job done (without

Is there a way to programmably flush the buffer in log4net

假如想象 提交于 2019-11-27 20:10:17
问题 I'm using log4net with AdoNetAppender. It's seems that the AdoNetAppender has a Flush method. Is there anyway I can call that from my code? I'm trying to create an admin page to view all the entries in the database log, and I will like to setup log4net with bufferSize=100 (or more), then I want the administrator to be able to click an button on the admin page to force log4net to write the buffered log entries to the database (without shutting down log4net). Is that possible? 回答1: Assuming you

std::endl crashes Windows 8, compiled using MinGW

混江龙づ霸主 提交于 2019-11-27 18:04:41
问题 I have 3 computers, two of which use Windows 8. Using the latest version of MinGW's g++ (4.8.1-4) my hello world program freezes whenever I compile and run on the Windows 8 computers but not in Windows 7. #include <iostream> int main() { std::cout << "Hello, World!" <<std::endl; return 0; } This compiles just fine in g++ but running a.exe will display "Hello, World!" then a window will pop up and say "a.exe has stopped working, Windows can check online for a solution to the program...." etc.

How to empty/flush Windows READ disk cache in C#?

被刻印的时光 ゝ 提交于 2019-11-27 13:47:29
If I am trying to determine the read speed of a drive, I can code a routine to write files to a filesystem and then read those files back. Unfortunately, this doesn't give an accurate read speed because Windows does disk read caching. Is there a way to flush the disk read cache of a drive in C# / .Net (or perhaps with Win32 API calls) so that I can read the files directly from the drive without them being cached? Why DIY? If you only need to determine drive speed and not really interested in learning how to flush I/O buffers from .NET, you may just use DiskSpd utility from http://research

c++ force std::cout flush (print to screen)

给你一囗甜甜゛ 提交于 2019-11-27 13:05:59
I have code such as the following: std::cout << "Beginning computations..."; // output 1 computations(); std::cout << " done!\n"; // output 2 The problem, however, is that often output #1 and output #2 appear (virtually) simultaneously. That is, often output #1 does not get printed to the screen until after computations() returns. Since the entire purpose of output #1 is to indicate that something is going on in the background (and thus to encourage patience from the user), this problem is not good. Is there any way to force the std::cout buffer to get printed before the computations() call?

C++ cout and cin buffers, and buffers in general

强颜欢笑 提交于 2019-11-27 12:28:41
Can someone explain the concept of buffers a bit more explicitly? I understand that buffers are data structures where characters are stored, and the place where the data is to be read from. What is the idea of flushing buffers? When a buffer is flushed, is this referring to the act of writing the characters stored in it? From the text: To avoid the overhead of writing in response to each output request, the library uses the buffer to accumulate the characters to be written, and flushes the buffer, by writing its contents to the output device, only when necessary. By doing so, it can combine

When Hibernate flushes a Session, how does it decide which objects in the session are dirty?

房东的猫 提交于 2019-11-27 12:27:34
My understanding of Hibernate is that as objects are loaded from the DB they are added to the Session. At various points, depending on your configuration, the session is flushed. At this point, modified objects are written to the database. How does Hibernate decide which objects are 'dirty' and need to be written? Do the proxies generated by Hibernate intercept assignments to fields, and add the object to a dirty list in the Session? Or does Hibernate look at each object in the Session and compare it with the objects original state? Or something completely different? Matt Quail Hibernate does