java/c++ 输出是如何工作的?cout<< System.out.print
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24662117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java/c++ How does output work? cout<< System.out.print
提问by Craig Lafferty
I am mostly concerned with Linux but answers involving windows are welcome.
我最关心的是 Linux,但欢迎回答涉及 Windows 的问题。
When I use System.out.println
or cout<<
what is actually happening and what happens when I do a cout
in a gui application (does it go anywhere)?
One case that I am interested in is the Netbeans IDE. When I run a java program in Netbeans what makes it possible for the IDE to "steal" the output from the program and display it?
当我使用System.out.println
或cout<<
实际发生的事情以及当我cout
在 gui 应用程序中执行 a 时会发生什么(它会去任何地方)?
我感兴趣的一个案例是 Netbeans IDE。当我在 Netbeans 中运行 java 程序时,是什么让 IDE 可以“窃取”程序的输出并显示它?
Update/Sidenote
更新/旁注
http://www.linfo.org/standard_output.html
One of the features of standard output is that it has a default destination but can easily be redirected (i.e., diverted) to another destination. That default destination is the display screen on the computer that initiated the program. Because the standard streams are plain text, they are by definition human readable.
http://www.linfo.org/standard_output.html
标准输出的特性之一是它有一个默认目的地,但可以很容易地重定向(即转移)到另一个目的地。该默认目标是启动程序的计算机上的显示屏。因为标准流是纯文本,所以根据定义,它们是人类可读的。
What is meant by "initiate the program"? I'm not very familiar with how the execution of a program begins but in the case of my netbeans example it's pretty clear that the IDE initiated the program. So what does that mean? When the program is being setup to be executed is there some meta data that is floating around letting the OS know that Netbeans is initiating the program?
“启动程序”是什么意思?我不太熟悉程序的执行是如何开始的,但在我的 netbeans 示例中,很明显 IDE 启动了程序。那是什么意思呢?当程序被设置为执行时,是否有一些元数据在浮动,让操作系统知道 Netbeans 正在启动程序?
采纳答案by Emanuele Paolini
When the program gets executed, three special file descriptors: stdin, stdout and stderr are associated to some device to determine how input and output is managed. If you execute a program from a terminal shell, stdin is associated to the keyboard, stdout and stderr to the terminal window. When you execute the program in a development environment usually stdout and stderr are displayed in some special console tabs. In other situations the output goes to some log file or maybe get discarded...
当程序被执行时,三个特殊的文件描述符:stdin、stdout 和 stderr 与某个设备相关联,以确定如何管理输入和输出。如果从终端 shell 执行程序,stdin 与键盘相关联,stdout 和 stderr 与终端窗口相关联。在开发环境中执行程序时,通常 stdout 和 stderr 会显示在一些特殊的控制台选项卡中。在其他情况下,输出会转到某个日志文件,或者可能会被丢弃...
System.out and cout are the objects representing the stdout stream in Java and C++.
System.out 和 cout 是表示 Java 和 C++ 中的 stdout 流的对象。