Tech Off Post

Single Post Permalink

View Thread: Why cout (c++) is so slow under Vista ?
  • User profile image

    Dexter said:
    evildictaitor said:

    cout is itself part of a runtime, the C/C++ runtime (also known as CRT in the Microsoft world). If you were to actually write low level code in C/C++ you'd have to use WriteFile(STD_OUTPUT_HANDLE, ...) on Windows and write(1, ...) on Unix.

    Anyway it's just a matter of defaults. gcc does line buffering by default (as far as I remember) while VC++ does not. You can always add something like this to your main funtion to change the default stdout buffering:

    char buf[1024];
    setvbuf(stdout, buf, _IOLBF, 1024);

    probably it is best to differentiate 'runtime (environment)' (in .NET and Java that would be the VMs) and 'runtime library' (in C++ that is a set of standard library functions). because c/c++ compiles directly to machine language, it does not run on top of any layer other than the physical machine itself.