digitalmars.D.learn - stdout - autoflushing
- Benji (15/15) Dec 03 2013 Hello,
- H. S. Teoh (14/31) Dec 03 2013 What about:
- Benji (2/32) Dec 03 2013 Thanks, I didn't think about that (I'm beginner)
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (5/9) Dec 03 2013 I am surprised that you need that. What is your platform?
- Benji (2/12) Dec 03 2013 I am using Xubuntu, 64bit, and GDC as compiler
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (7/21) Dec 03 2013 I've known this to be the case for cin and cout of C++. So, I've been
- John Colvin (4/29) Dec 04 2013 The 'tie' is sometimes convenient, but it's not good in Unix
- Jesse Phillips (5/20) Dec 03 2013 I haven't seen this behavior, though I haven't used GDC (debian
- Adam D. Ruppe (4/5) Dec 03 2013 Any IDE? I've seen ide consoles buffer differently because the
- Benji (4/9) Dec 04 2013 I'm using using Eclipse Kepler Standard(4.3).
- Dejan Lekic (6/23) Dec 06 2013 I doubt. Your IDE is buffering application's streams.
- Adam D. Ruppe (6/9) Dec 06 2013 You know though, this happens often enough that maybe we should
Hello, in order to have correctly displayed output (before reading something from stdin), I must call stdout.flush(). Sometimes, it's really annoying, especially when it is necessarry to call it 10 times. For example: write("Enter some string: "); stdout.flush(); string a = readln(); write("And again please: "); stdout.flush(); string b = readln(); ... Is there any way to prevent this?
Dec 03 2013
On Tue, Dec 03, 2013 at 06:12:20PM +0100, Benji wrote:Hello, in order to have correctly displayed output (before reading something from stdin), I must call stdout.flush(). Sometimes, it's really annoying, especially when it is necessarry to call it 10 times. For example: write("Enter some string: "); stdout.flush(); string a = readln(); write("And again please: "); stdout.flush(); string b = readln(); ... Is there any way to prevent this?What about: void prompt(A...)(string fmt, A args) { writef(fmt, args); stdout.flush(); return readln(); } auto a = prompt("Enter your name: "); auto b = prompt("Enter your age: ").to!int; ... // etc. T -- If you think you are too small to make a difference, try sleeping in a closed room with a mosquito. -- Jan van Steenbergen
Dec 03 2013
On Tuesday, 3 December 2013 at 17:49:32 UTC, H. S. Teoh wrote:On Tue, Dec 03, 2013 at 06:12:20PM +0100, Benji wrote:Thanks, I didn't think about that (I'm beginner)Hello, in order to have correctly displayed output (before reading something from stdin), I must call stdout.flush(). Sometimes, it's really annoying, especially when it is necessarry to call it 10 times. For example: write("Enter some string: "); stdout.flush(); string a = readln(); write("And again please: "); stdout.flush(); string b = readln(); ... Is there any way to prevent this?What about: void prompt(A...)(string fmt, A args) { writef(fmt, args); stdout.flush(); return readln(); } auto a = prompt("Enter your name: "); auto b = prompt("Enter your age: ").to!int; ... // etc. T
Dec 03 2013
On 12/03/2013 09:12 AM, Benji wrote:Hello, in order to have correctly displayed output (before reading something from stdin), I must call stdout.flush().I am surprised that you need that. What is your platform? Normally, stdin and stdout are "tied". Reading from stdin flushes stdout automatically. Ali
Dec 03 2013
On Tuesday, 3 December 2013 at 19:33:47 UTC, Ali Çehreli wrote:On 12/03/2013 09:12 AM, Benji wrote:I am using Xubuntu, 64bit, and GDC as compilerHello, in order to have correctly displayed output (before reading something from stdin), I must call stdout.flush().I am surprised that you need that. What is your platform? Normally, stdin and stdout are "tied". Reading from stdin flushes stdout automatically. Ali
Dec 03 2013
On 12/03/2013 12:36 PM, Benji wrote:On Tuesday, 3 December 2013 at 19:33:47 UTC, Ali Çehreli wrote:I've known this to be the case for cin and cout of C++. So, I've been assuming that to be universally true. Apparently not for C and D behavior is based on C. I wish std.stdio gave us C++'s 'tie'. Ali P.S. This makes some of the examples at ddili.org incorrect as I never call flush. :-/On 12/03/2013 09:12 AM, Benji wrote:I am using Xubuntu, 64bit, and GDC as compilerHello, in order to have correctly displayed output (before reading something from stdin), I must call stdout.flush().I am surprised that you need that. What is your platform? Normally, stdin and stdout are "tied". Reading from stdin flushes stdout automatically. Ali
Dec 03 2013
On Tuesday, 3 December 2013 at 21:23:19 UTC, Ali Çehreli wrote:On 12/03/2013 12:36 PM, Benji wrote:The 'tie' is sometimes convenient, but it's not good in Unix style stdin/stout piping or similar situations with lots of simultaneous input and output.On Tuesday, 3 December 2013 at 19:33:47 UTC, Ali Çehreli wrote:I've known this to be the case for cin and cout of C++. So, I've been assuming that to be universally true. Apparently not for C and D behavior is based on C. I wish std.stdio gave us C++'s 'tie'. Ali P.S. This makes some of the examples at ddili.org incorrect as I never call flush. :-/On 12/03/2013 09:12 AM, Benji wrote:I am using Xubuntu, 64bit, and GDC as compilerHello, in order to have correctly displayed output (before reading something from stdin), I must call stdout.flush().I am surprised that you need that. What is your platform? Normally, stdin and stdout are "tied". Reading from stdin flushes stdout automatically. Ali
Dec 04 2013
On Tuesday, 3 December 2013 at 20:36:22 UTC, Benji wrote:On Tuesday, 3 December 2013 at 19:33:47 UTC, Ali Çehreli wrote:I haven't seen this behavior, though I haven't used GDC (debian is close enough right). This has been how I've retrieved user data: https://github.com/JesseKPhillips/JPDLibs/blob/cmdln/cmdln/interact.d#L60On 12/03/2013 09:12 AM, Benji wrote:I am using Xubuntu, 64bit, and GDC as compilerHello, in order to have correctly displayed output (before reading something from stdin), I must call stdout.flush().I am surprised that you need that. What is your platform? Normally, stdin and stdout are "tied". Reading from stdin flushes stdout automatically. Ali
Dec 03 2013
On Tuesday, 3 December 2013 at 20:36:22 UTC, Benji wrote:I am using Xubuntu, 64bit, and GDC as compilerAny IDE? I've seen ide consoles buffer differently because the runtime sees the target as a pipe instead of a user-interactive terminal.
Dec 03 2013
On Tuesday, 3 December 2013 at 21:47:19 UTC, Adam D. Ruppe wrote:On Tuesday, 3 December 2013 at 20:36:22 UTC, Benji wrote:I'm using using Eclipse Kepler Standard(4.3). I tryied it via shell and everything worked fine also without stdout.flush().I am using Xubuntu, 64bit, and GDC as compilerAny IDE? I've seen ide consoles buffer differently because the runtime sees the target as a pipe instead of a user-interactive terminal.
Dec 04 2013
Benji wrote:Hello, in order to have correctly displayed output (before reading something from stdin), I must call stdout.flush(). Sometimes, it's really annoying, especially when it is necessarry to call it 10 times. For example: write("Enter some string: "); stdout.flush(); string a = readln(); write("And again please: "); stdout.flush(); string b = readln(); ... Is there any way to prevent this?I doubt. Your IDE is buffering application's streams. -- Dejan Lekic dejan.lekic (a) gmail.com http://dejan.lekic.org
Dec 06 2013
On Friday, 6 December 2013 at 20:39:22 UTC, Dejan Lekic wrote:Benji wrote:You know though, this happens often enough that maybe we should just throw in a stdout.flush to the global readln function. I wouldn't put it on File.readln since that's likely wrong anyway, but on the global one it is probably what people want/expect anyway.Is there any way to prevent this?I doubt. Your IDE is buffering application's streams.
Dec 06 2013