System.out、stdout和cout是完全相同的吗? 系统、输出、STDUT和CUT分别在java、C++和C++中完全相同?p> 为什么有三个不同的名字用于同一件事情(尤其是当C,C++和java有很多共同点)?< /P>
另外,我知道它们的用途,但它们到底是什么,在引擎盖下,我的意思是?它们是相同的东西,但它们的类型不同。例如,System.out、stdout和cout是完全相同的吗? 系统、输出、STDUT和CUT分别在java、C++和C++中完全相同?p> 为什么有三个不同的名字用于同一件事情(尤其是当C,C++和java有很多共同点)?< /P>,java,c++,c,iostream,stdio,Java,C++,C,Iostream,Stdio,另外,我知道它们的用途,但它们到底是什么,在引擎盖下,我的意思是?它们是相同的东西,但它们的类型不同。例如,stdout是一个文件*,cout是一个std::ostream。因为C++支持这两种语言,所以不同的名称是必需的。 在后台,所有这些变量都引用调用进程的标准输出。它是三个文件描述符之一(stdin,stdout,stderr),在生成新进程时,操作系统总是打开这些文件描述符。写入此文件描述符的所有内容都会出现在屏幕上或重定向到stdout的任何位置(使用或>shell操作符)。cout基
stdout
是一个文件*
,cout
是一个std::ostream
。因为C++支持这两种语言,所以不同的名称是必需的。
在后台,所有这些变量都引用调用进程的标准输出。它是三个文件描述符之一(
stdin
,stdout
,stderr
),在生成新进程时,操作系统总是打开这些文件描述符。写入此文件描述符的所有内容都会出现在屏幕上或重定向到stdout
的任何位置(使用
或>
shell操作符)。cout
基本上与stdout
相同,但区别在于cout
属于ostream
类型(这本质上意味着可以使用输入格式化数据。理论上,它们是相同的东西,都发送到标准输出
<> P>但是,在C和C++中,CUT建立在STDUT之上,添加了St.OUT提供的一些格式,因为java没有指针的概念,所以SUBE系统被重新设计成使用PrtSt流做类似CUT的任务。
PritnStream提供了一些额外的功能,例如,PrintStream不会抛出IOException,而是设置一个内部错误标志,然后可以使用checkError访问该标志
<> P>我认为命名约定是因为每个语言的设计者都是不同的。C,C++与UNIX紧密相关,因此他们使用了诸如标准输出和控制台等术语。java被设计成面向对象,因此java的创建者决定把它命名为有点不同。< /P> < P>它们是每种语言SP。写入程序“标准输出”文件的特定方式,这一概念起源于C/UNIX。它们为执行输出提供的确切函数/方法不同
<>代码也可以提到,C++中的代码都是可用的,因为它试图成为C语言的超集,但是混合这两个用法可能是个坏主意,除非你完全禁用两个缓冲区。我不知道这两个共享缓冲区的任何要求,所以可能是OutPU。如果你把它们混在一起,t的顺序就会出错。“文件描述符”不是C语言的一部分,而是POSIX。说stdout
“返回一个文件描述符”是不正确的语言用法(一个变量怎么可能“返回”任何东西?)C、C++和java只是语法上相似的,但语义却很不相同。它们是不同的计算机语言。这些语言都不是语言的一部分。它们是语言的一部分。它们不是关键字,不是语言规范的一部分。
/**
* Initialize the system class. Called after thread initialization.
*/
private static void initializeSystemClass() {
props = new Properties();
initProperties(props);
sun.misc.Version.init();
// Workaround until DownloadManager initialization is revisited.
// Make JavaLangAccess available early enough for internal
// Shutdown hooks to be registered
setJavaLangAccess();
// Gets and removes system properties that configure the Integer
// cache used to support the object identity semantics of autoboxing.
// At this time, the size of the cache may be controlled by the
// vm option -XX:AutoBoxCacheMax=<size>.
Integer.getAndRemoveCacheProperties();
// Load the zip library now in order to keep java.util.zip.ZipFile
// from trying to use itself to load this library later.
loadLibrary("zip");
FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
setIn0(new BufferedInputStream(fdIn));
setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));
setErr0(new PrintStream(new BufferedOutputStream(fdErr, 128), true));
// Setup Java signal handlers for HUP, TERM, and INT (where available).
Terminator.setup();
// Initialize any miscellenous operating system settings that need to be
// set for the class libraries. Currently this is no-op everywhere except
// for Windows where the process-wide error mode is set before the java.io
// classes are used.
sun.misc.VM.initializeOSEnvironment();
// Set the maximum amount of direct memory. This value is controlled
// by the vm option -XX:MaxDirectMemorySize=<size>. This method acts
// as an initializer only if it is called before sun.misc.VM.booted().
sun.misc.VM.maxDirectMemory();
// Set a boolean to determine whether ClassLoader.loadClass accepts
// array syntax. This value is controlled by the system property
// "sun.lang.ClassLoader.allowArraySyntax". This method acts as
// an initializer only if it is called before sun.misc.VM.booted().
sun.misc.VM.allowArraySyntax();
// Subsystems that are invoked during initialization can invoke
// sun.misc.VM.isBooted() in order to avoid doing things that should
// wait until the application class loader has been set up.
sun.misc.VM.booted();
// The main thread is not added to its thread group in the same
// way as other threads; we must do it ourselves here.
Thread current = Thread.currentThread();
current.getThreadGroup().add(current);
}
/**
* A handle to the standard output stream. Usually, this file
* descriptor is not used directly, but rather via the output stream
* known as <code>System.out</code>.
* @see java.lang.System#out
*/
public static final FileDescriptor out = standardStream(1);