/*  The synchronization referred to is @e only that between the standard
* C facilities (e.g., stdout) and the standard C++ objects (e.g.,
* cout). User-declared streams are unaffected. See
* https://gcc.gnu.org/onlinedocs/libstdc++/manual/fstreams.html#std.io.filestreams.binary
*/
很多人对于同步的问题有误解
其实同步只针对cin, cout, cerr, clog(加上宽字符版本)共八个有影响,gcc的实现中是特意为它们定义了stdio_stream_buf的,而
且编译器开后门保证它们只初始化一次
而我们自己定义流的话,istream. ostream, fstream, sstream都要有一个stream_buf丢进去,这时候,我们根本没法使用stdio_stream_buf
能用到的就是file_buf和string_buf, file_buf底层使用的read write等 无缓冲的api,缓冲区是在stream_buf中自己管理的
所以自定义的流调用sync_with_stdio是没有意义的:而且要注意sync_with_stdio是一个static成员函数(来自ios_base类),影响是全局性的!

sync_with_stdio的更多相关文章

  1. std::ios::sync_with_stdio(false);

    这句语句是用来取消cin的同步,什么叫同步呢?就是iostream的缓冲跟stdio的同步.如果你已经在头文件上用了using namespace std;那么就可以去掉前面的std::了.取消后就c ...

  2. 1, sync_with_stdio(), tie()的应用

    一.sync_with_stdio() 这个函数是一个“是否兼容stdio”的开关,C++为了兼容C,保证程序在使用了std::printf和std::cout的时候不发生混乱,将输出流绑在了一起. ...

  3. 关于ios::sync_with_stdio(false)

    作用就是取消同步,这样的话使用cin就和使用scanf效率相似. 但是今天在做题的时候碰到一点小问题,就是在关闭同步的时候使用scanf是交了一发代码,然后RE了(经检查scanf没有写错),而把关同 ...

  4. 关于C++中ios::sync_with_stdio(false)

    粘贴自:https://blog.csdn.net/weixin_44015865/article/details/84974373 在C++中的输入和输出有两种方式,一种是scanf和printf, ...

  5. cin.tie与sync_with_stdio加速输入输出

    在LeetCode上练习习题的时候每次AC之后都会去看别人的代码,几乎每次都能遇到cin.tie与sync_with_stdio.类似这样: static auto x = [](){ std::io ...

  6. ios::sync_with_stdio(false)提高C++读写速度

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:ios::sync_with_stdio(false)提高C++读写速度     本文地址:h ...

  7. 关于std::ios::sync_with_stdio(false)

    std::ios::sync_with_stdio(false); 很多C++的初学者可能会被这个问题困扰,经常出现程序无故超时,最终发现问题处在cin和cout上,(甚至有些老oier也会被这个问题 ...

  8. 关于ios::sync_with_stdio(false);和 cin.tie(0)加速c++输入输出流

    原文地址:http://www.hankcs.com/program/cpp/cin-tie-with-sync_with_stdio-acceleration-input-and-output.ht ...

  9. std::ios::sync_with_stdio和tie()——给cin加速

    平时在Leetcode上刷题的时候,总能看到有一些题中最快的代码都有这样一段 static const auto init = []() { std::ios::sync_with_stdio(fal ...

随机推荐

  1. C# DateTime 格式化 奇怪问题!

    使用 DateTime.Now.ToString("MM/dd") 本地显示 06/16 window sevcie 2003  显示是 06-16 解决方法: DateTime. ...

  2. setWinldowRgn

    CRgn(HRGN) SetWindowRgn setRgn{ CRgn rgnRect; CRgn rgnHole; //获取窗口大小 CRect rcWnd; GetWindowRect(& ...

  3. 张艾迪(创始人): 整合全新的UIW.AD概念

    The World No.1 Girl :Eidyzhang The World No.1 Internet Girl :Eidyzhang AOOOiA.global Founder :Eidyzh ...

  4. sqlite数据库的使用helper

    public class SQLiteHelper     {         //public static String ConnectionString = "Data Source= ...

  5. python 学习2

    在1的基础上 settings.py blog/models.py: 打开一个cmd, net start mysql ,启动mysql服务 mysql -uroot -p 再在py_fir目录下打开 ...

  6. 用于阻止div上的事件和div上的按钮的事件同时触发

    event.stopPropagation()  阻止事件冒泡  用于ie11以上

  7. 每天一个percona 工具 --- pt-kill

    主要用途:pt-kill是用来kill MySQL连接的一个工具,在MySQL中因为空闲连接较多导致超过最大连接数,或某个有问题的sql导致mysql负载很高时,需要将其KILL掉来保证服务器正常运行 ...

  8. 一道Integer面试题引发的对Integer的探究

    面试题: //在jdk1.5的环境下,有如下4条语句: Integer i01 = 59; int i02 = 59; Integer i03 =Integer.valueOf(59); Intege ...

  9. STC12C5A60S2 双串口通信

    STC12C5A60S2单片机是一款功能比较强大的单片机,它拥有两个全双工串行通信接口,串口1的功能及操作与传统51单片机串行口相同:特殊的是STC12C5A60S2单片机内部有一个独立波特率发生器, ...

  10. .net中如何发送HTTP请求网络资源

    应用场景 应该说只要是需要通过发送Http请求获取网络资源的地方都要使用它,网络资源可以是指以URI来表示的资源,比如web api接口等. HttpWebRequest .net2.0 ~ .net ...