cout语句在c ++中如何工作?以及如何将输出显示在屏幕上? [英] how the cout statement works in c++? and how the output is displayed to the screen with it?

查看:282
本文介绍了cout语句在c ++中如何工作?以及如何将输出显示在屏幕上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

cout语句如何在c ++中工作?

how the cout statement works in c++? and how the output is displayed to the screen with it?

推荐答案

read ^ ]


这是一个长期的问题,涉及大量概念,其中一些与
相关 语言标准库以及一些与平台特定实现有关的内容.

cout


首先,std::cout全局变量,在
中声明 < iostream>并在c ++运行时支持库中的某个位置定义.

它的类型是从std :: ostream派生的内部类,它嵌入一个成员
衍生自std :: streambuff和类型为std :: locale的成员.

当你写
That''s a long problem that in involve a large number of concepts, some related to
the language standard library and some related to the platform specific implementation.

cout


Firsts of all, std::cout is a global variable, declared in
<iostream> and defined somewhere in the c++ runtime support library.

It''s type is an internal class, derived from std::ostream, that embed a member
derived from std::streambuff and a member of type std::locale.

when you write
std::cout << 45;



功能
std::ostream& operator<<(std::ostream&, const int&)
被称为.

对于任何内置类型,此功能都有一个变体,以及其他一些
适用于const char*const std::string等特定类型.

取决于函数的变体(即:取决于参数类型)
-找到与流相关的语言环境,并找到正确的类型到文本转换方面.
(对于整数,这是std :: num_put facet类)
-调用put函数,将数字转换为其代表文本
要存储到与streambuff关联的流中.

缓冲区已满时(或调用缓冲区同步功能时,例如
通过std :: endl操纵器)将其内容写入关联的文件.

对于cout,缓冲区的关联文件是"CON:"符号文件,它表示
操作系统的代表标准输出.

控制台


至此,C ++结束了其工作,并且在操作中将文本写入CON文件中.
系统映射到将内容分发到应用程序控制台"的内部流程.

这只是一个特定的窗口,其窗口操作包括使用
缓冲区中显示的文本,是字符和相关属性的矩阵,是
用CON文件缓冲区检索的字符或通过适当解析它们填充的字符
(例如,\ n将光标移到下一行,\ b将光标移回下一行,等等)每次该文件为
通知要更改.

低级API



绘画"操作包括检索字符并将其提供给
TextOut API(或类似的),该API使用选定的字体转换
各自图像中的字符序列,并复制到正确位置
进入设备上下文",则-fro屏幕-是位于
上的字节序列 表示图形适配器的光栅的内存映射页面,其处理器
将图像位转换为驱动监视器的模拟信号时要充电n.

最后一点在显示其他应用程序的其他内容方面没有区别.



the function
std::ostream& operator<<(std::ostream&, const int&)
is called.

There is a variant of this function for any of the built-in types plus some other
for particular types like const char* or const std::string etc.

Depending on the variant of the function (that is: depending on the parameter type)
- the stream associated locale is found and the proper type-to-text conversion facet is found.
(for an integer, this is the std::num_put facet class)
- the put function is called, converting the number into its representative text
to be stored into the stream associated streambuff.

When the buffer is full (or when the buffer sync function is called, for example
by means of the std::endl manipulator) its content is written to thje associated file.

For cout, the buffer''s associated file is the "CON:" symbolic file, that represent
what for the operating system represent the standard output.

The console


At this point, C++ ended its job, and a text is written into the CON file the operating
system mapped to an internal process that dispatches the content to the "application console".

This is just a particular window whose window-procedure consist in panting a window with
the text present on a buffer that is a matrix of characters and related attributes that is
filled-in with the characters retrieved by the CON file buffer or by appropriately parsing them
(for example \n moves the cursor to the next line, \b moves it back etc.) every time that file is
notified to be changed.

Low level API



The "painting" action consist in retrieving the characters and give them to the
TextOut API (or similar) that, using the selected font, converts the
character sequence in their respective images, that are copied in the proper position
into the "device context", that -fro the screen- is a sequence of bytes located on
a memory mapped page that represent the raster of the graphic adapter, whose processor
is n charge to transform the image bits into the analog signal that drives the monitor.

This last point has no difference in respect to display whatever else for whatever other application.


这篇关于cout语句在c ++中如何工作?以及如何将输出显示在屏幕上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆