当前位置: 首页 > wzjs >正文

cms 网站后台网站页面设计培训班

cms 网站后台,网站页面设计培训班,公司网站建设费用估计,装企营销系统目录 换行符刷新缓冲区(c和c通用) 输入事件到来(c和c通用) 控制符flush(c特有) 控制符endl(c特有) c库函数:fflush刷新缓冲区(c特有) sync(linux) fsync(linux) fdatasync (linux) 在使用printf或者cout等将数据输出到显示器上时&…

目录

换行符刷新缓冲区(c和c++通用)

输入事件到来(c和c++通用)

控制符flush(c++特有)

控制符endl(c++特有)

c库函数:fflush刷新缓冲区(c特有)

sync(linux)

fsync(linux)

fdatasync (linux)


 在使用printf或者cout等将数据输出到显示器上时,数据会先进入对应的输出缓冲区,只有当缓冲区被刷新时,数据才会真正来到显示器。

换行符刷新缓冲区(c和c++通用)

#include <iostream>
#include <stdio.h>
#include <unistd.h>
using namespace std;// 换行符刷新缓冲区
int main()
{// cout不会直接将“123”输出到显示器上,而是将其发送到输出缓冲区// 输出缓冲区收到换行符后,会刷新输出缓冲区至显示器上// 也可以从面向对象的角度思考一下这个问题:// 我想要输出一些数据到显示器上// cout用于将数据输出到显示器上// 可是我想一次发一个完整的数据给显示器,那么什么时候才是这个完整的数据呢// "\n"告诉cout这个完整的数据我写完了,你去发给显示器吧cout << 123;sleep(3);cout << "\n";sleep(3);return 0;
} 

输入事件到来(c和c++通用)

#include <iostream>
#include <stdio.h>
#include <unistd.h>
using namespace std;// 输入事件到来
int main()
{// 当需要输入时,会刷新输出缓冲区至显示器上cout << "enter a number: ";int a;cin >> a;return 0;
} 

控制符flush(c++特有)

#include <iostream>
#include <stdio.h>
#include <unistd.h>
using namespace std;// 控制符flush
int main()
{cout << 123;sleep(3);// cout << flush; //--->实际上ostream类对插入运算符<<进行了重载。cout << flush被替换成flush(cout)flush(cout);sleep(3);return 0;
} 

控制符endl(c++特有)

#include <iostream>
#include <stdio.h>
#include <unistd.h>
using namespace std;// 控制符endl
int main()
{// endl也会刷新cout对应的输出缓冲区至显示器上,并添加换行符'\n'cout << 123;sleep(3);cout << endl;sleep(3);return 0;
} 

c库函数:fflush刷新缓冲区(c特有)

#include <iostream>
#include <stdio.h>
#include <unistd.h>
using namespace std;// c库函数:fflush刷新缓冲区
// int fflush(FILE *stream);
int main()
{// endl也会刷新cout对应的输出缓冲区至显示器上,并添加换行符'\n'printf("123");sleep(3);fflush(stdout);sleep(3);return 0;
}

sync(linux)

        将所有文件已修改的数据从内核缓冲区写回存储设备;将所有文件的元数据(如文件大小、权限、时间戳等)从内核缓冲区写回存储设备。

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/sync.h>int main() {int fd = open("test.txt", O_WRONLY | O_CREAT, 0644);if (fd == -1) {perror("open");return 1;}const char *message = "Hello, sync!";// write并不会把数据直接写入磁盘,而是写入到该文件对应的内核缓冲区ssize_t bytes_written = write(fd, message, sizeof(message) - 1);if (bytes_written == -1) {perror("write");close(fd);return 1;}// 调用sync函数确保数据写入磁盘// 刷新所有内核缓冲区,包括这个文件和其他文件对应的内核缓冲区// 会刷新每个文件对应的内核缓冲区至各自对应的磁盘区域上sync();close(fd);return 0;
}

fsync(linux)

        将特定一个文件已修改的数据从内核缓冲区写回存储设备;将特定一个文件的元数据(如文件大小、权限、时间戳等)从内核缓冲区写回存储设备。

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>int main() {int fd = open("test_fsync.txt", O_WRONLY | O_CREAT, 0644);if (fd == -1) {perror("open");return 1;}const char *message = "Hello, fsync!";ssize_t bytes_written = write(fd, message, sizeof(message) - 1);if (bytes_written == -1) {perror("write");close(fd);return 1;}// 调用fsync函数确保该文件对应内核缓冲区数据和元数据写入磁盘if (fsync(fd) == -1) {perror("fsync");close(fd);return 1;}close(fd);return 0;
}

        这里,在写入数据后,我们调用 fsyncfsync 会确保不仅文件内容(数据)被写入磁盘,而且文件的元数据,如文件大小、权限、时间戳等也被同步更新到磁盘。这对于需要严格一致性的应用场景非常重要,比如文件系统的元数据更新操作。

fdatasync (linux)

        只保证将特定一个文件对应的内核缓冲区中的数据写入到磁盘。

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>int main() {int fd = open("test_fdatasync.txt", O_WRONLY | O_CREAT, 0644);if (fd == -1) {perror("open");return 1;}const char *message = "Hello, fdatasync!";ssize_t bytes_written = write(fd, message, sizeof(message) - 1);if (bytes_written == -1) {perror("write");close(fd);return 1;}// 调用fdatasync函数确保该文件内核缓冲区数据写入磁盘if (fdatasync(fd) == -1) {perror("fdatasync");close(fd);return 1;}close(fd);return 0;
}

文章转载自:

http://mk9uGGo9.kwqcy.cn
http://GJw5im5N.kwqcy.cn
http://QHJTLD27.kwqcy.cn
http://aNh31NGL.kwqcy.cn
http://nlXWKqvM.kwqcy.cn
http://C7qIoktc.kwqcy.cn
http://x5iVdZS5.kwqcy.cn
http://fgjAlisV.kwqcy.cn
http://5BWNLG4J.kwqcy.cn
http://ZFG9VbYD.kwqcy.cn
http://XDDwkUHT.kwqcy.cn
http://WEWgIShN.kwqcy.cn
http://QrWucTEN.kwqcy.cn
http://MvX3Zp7O.kwqcy.cn
http://LN7hEgpE.kwqcy.cn
http://CNjs6X6J.kwqcy.cn
http://qV7PzHqk.kwqcy.cn
http://iD0ijfhy.kwqcy.cn
http://SNJ9nLpe.kwqcy.cn
http://3uoX09MG.kwqcy.cn
http://yMAi5zTM.kwqcy.cn
http://YimvK9lV.kwqcy.cn
http://8r2vPEWg.kwqcy.cn
http://Yg5QV0NF.kwqcy.cn
http://0anI4Pbk.kwqcy.cn
http://AO8asHCc.kwqcy.cn
http://5ka4MFK6.kwqcy.cn
http://pZBeMKns.kwqcy.cn
http://yWHlIgD5.kwqcy.cn
http://5WUorNAv.kwqcy.cn
http://www.dtcms.com/wzjs/684231.html

相关文章:

  • 网站的企业特色展示广告公司名字400个
  • 深圳装饰网站建设网络营销有必要学吗
  • 网站建设流程笔记南阳高质量建设大市网站
  • 建设网站要多久到账在天极网做网站有效果吗
  • 适合做外链的网站太原网站推广只选中联传媒
  • 公司网站打开很慢wordpress社区主题
  • 成都网站建设公司服务商wordpress优雅的暂停
  • 网站建设服务器配置学历提升文案
  • 17一起做网站普宁站网站怎么做伪静态
  • 2017做哪些网站致富重庆小潘seo
  • 怎么敲代码做网站遵义网站制作一般多少钱
  • 官网的网站设计公司建设摩托车官网旗舰店
  • 有什么可以在线做数学题的网站快速创建一个网页
  • 外贸网站运营怎么做以网站域名做邮箱
  • 旅游网站建设模板wordpress可以移动端
  • 合肥电子商务网站建设代码导入wordpress
  • 电子商务网站开发的预期目标建设外国商城网站
  • 百度竞价做网站建设长春网站建设v1
  • 建设银行打印回单网站一级建造师求职平台
  • 网站全程设计技术wordpress菜单怎么设置
  • 免费建网站视频教程oa厂家排名
  • 做视频搬运工的网站明光网站
  • 社区网站免费制作未来网站发展方向
  • 西安市做网站怎样查网站谁做的
  • 北京建设学院网站基于wordpress的商城系统
  • 注重网站内容维护西湖区高端网站建设
  • 影响网站用户体验大气宽屏网站模板
  • 安阳网络公司佛山网站建设优化制作公司
  • 纳税服务网站建设情况软件开发的生命周期
  • 同城网站开发建筑企业公司简介怎么写