1

I'm a beginner C++ programmer.I would like to know that Is it possible to output to console windows without using iostream header file?

the answer of the question is actually Yes ! but How?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Amirreza
  • 21
  • 3
  • A search for [console functions on MSDN](http://msdn.microsoft.com/en-us/library/windows/desktop/ms682073%28v=vs.85%29.aspx) should probably turn something up. – Some programmer dude Sep 06 '14 at 09:43
  • Why? You can with `write` – Ed Heal Sep 06 '14 at 09:44
  • 1
    You can use [c style I/O functions](http://en.cppreference.com/w/c/io/fprintf), but why? – πάντα ῥεῖ Sep 06 '14 at 09:44
  • Because i would like to know that how iostream does this? – Amirreza Sep 06 '14 at 09:47
  • 2
    @Amirreza - How deep do you wish to go. The Electric is generated by fission. This occurs because U235/U238 ... Uranium is produced by the stars – Ed Heal Sep 06 '14 at 09:52
  • @EdHeal,I wish to go deep a little more :D . So until now i know that is call WinAPI,Is that true? – Amirreza Sep 06 '14 at 09:54
  • _"how iostream does this?"_ Most of the `std` implementations will use low level [`read()`](http://en.cppreference.com/w/c/io/fread) and [`write()`](http://en.cppreference.com/w/c/io/fwrite) functions. – πάντα ῥεῖ Sep 06 '14 at 09:54
  • @πάνταῥεῖ I mean that are these functions existed on all operating systems(Mac,Win,Linux)? – Amirreza Sep 06 '14 at 09:58
  • @Amirreza Yes, they are available on all POSIX API compliant systems. Windows is partly POSIX compliant, especially the I/O parts are. – πάντα ῥεῖ Sep 06 '14 at 10:00
  • possible duplicate of [How are all the c++ functions finally defined?](http://stackoverflow.com/questions/23460614/how-are-all-the-c-functions-finally-defined) – edmz Sep 06 '14 at 10:04
  • @πάνταῥεῖ: Windows' Posix subsystem was removed in Windows Vista, I think it was. Anyway it was very incomplete. The phasing out began already in Windows NT 4.x with the introduction of Services for Unix (SFU). At one time it was a bit silly. You could install Microsoft's Interix-based SFU and get a very old g++ compiler, from Microsoft. – Cheers and hth. - Alf Sep 06 '14 at 10:11
  • So how iostream reaches suitable API in linux,@Cheersandhth.-Alf says that POSIX API is removed! – Amirreza Sep 06 '14 at 21:40

1 Answers1

2

You can always delve down to the C library level, using e.g. printf.

If you don't want to use the standard library at all then you have to use platform-specific functionality. In Windows there are many layers here, much like the C++ versus C layers in the standard library. The highest Windows API layer is the WriteFile function, and below that, WriteConsole, then perhaps WriteConsoleOutput, so on, check it out.

Note that there are at least two open source projects to provide more reasonable console functionality in Windows, namely Console2 at SourceForge and mintty at Google Code.

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
  • 1
    Thank you for your answer. I used console output in my question just for an example.I know that applications can call operating systems API to do something that they actually want and i also know that the functions are different(atleast in name) in different operating systems.But my main question is that How C,C++ library actually finds suitable API? – Amirreza Sep 06 '14 at 10:01
  • 3
    To get answers to a different question, ask that question. Tip: try to be very clear. – Cheers and hth. - Alf Sep 06 '14 at 10:06