On Thu, Jun 23, 2011 at 3:16 PM, Walter Bright <newshou...@digitalmars.com>wrote:
> On 6/23/2011 1:03 PM, Jimmy Cao wrote: > >> On Thu, Jun 23, 2011 at 2:52 PM, Walter Bright < >> newshou...@digitalmars.com >> <mailto:newshound2@**digitalmars.com <newshou...@digitalmars.com>>> >> wrote: >> >> On 6/23/2011 11:48 AM, Jimmy Cao wrote: >> >> But that's not possible (to set it to line-buffering) on Windows, >> right? >> >> >> Sure it is, using the usual C functions. This is not a Windows thing, >> it's a >> C runtime library thing. >> >> >> How do you make it have line-buffering? >> It's not possible to set line-buffering in Windows using setvbuf, it >> seems: >> http://msdn.microsoft.com/en-**us/library/86cebhfs(v=vs.71).**aspx<http://msdn.microsoft.com/en-us/library/86cebhfs(v=vs.71).aspx> >> _IOFBF and _IOLBF are the same. >> >> I think this is the cause of the strange flushing inconsistencies with >> stdio.d >> from my earlier example on Windows. >> > > I can't say anything about VC++, but dmd on Windows is designed to work > with DMC++. > > http://www.digitalmars.com/**rtl/stdio.html#setvbuf<http://www.digitalmars.com/rtl/stdio.html#setvbuf> > On Windows: import std.stdio; extern(C) int getch(); void main() { stdout.setvbuf(100, _IOLBUF); string mystr = "Hello\n"; fwrite(mystr.ptr, mystr[0].sizeof, mystr.length, stdout.getFP); // FPUTC('\n', cast(_iobuf*)stdout.getFP); getch(); } Am I doing anything wrong there? That code as it is does not flush until after a keypress (when the program terminates). Uncomment the FPUTC call and it does flush before the keypress.