pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

ios_base::sync_with_stdio(false) 的意義;cin.tie(NULL);

Significance of ios_base::sync_with_stdio(false); cin.tie(NULL);(ios_base::sync_with_stdio(false) 的意義;cin.tie(NULL);)
本文介紹了ios_base::sync_with_stdio(false) 的意義;cin.tie(NULL);的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

包含的意義是什么

ios_base::sync_with_stdio(false);
cin.tie(NULL);

在 C++ 程序中?

在我的測試中,它加快了執行時間,但是否有我應該擔心的測試用例包含這個?

In my tests, it speeds up the execution time, but is there a test case I should be worried about by including this?

這兩個語句是否總是必須在一起,還是第一個就足夠了,即忽略cin.tie(NULL)?

Do the 2 statements always have to be together, or is the first one sufficient, i.e., ignoring cin.tie(NULL)?

此外,如果其值已設置為 false,是否允許同時使用 C 和 C++ 命令?

Also, is it permissible to use simultaneous C and C++ commands if its value has been set to false?

https://www.codechef.com/viewsolution/7316085

以上代碼運行良好,直到我在 C++ 程序中使用 scanf/printf 并將值設為 true.在這種情況下,它給出了分段錯誤.對此有什么可能的解釋?

The above code worked fine, until I used scanf/printf in a C++ program with the value as true. In this case, it gave a segmentation fault. What could be the possible explanation for this?

推薦答案

這兩個調用意義不同,與性能無關;它加快了執行時間這一事實(或可能是)只是一個副作用.您應該了解它們各自的作用,不要因為它們看起來像是優化而盲目地將它們包含在每個程序中.

The two calls have different meanings that have nothing to do with performance; the fact that it speeds up the execution time is (or might be) just a side effect. You should understand what each of them does and not blindly include them in every program because they look like an optimization.

ios_base::sync_with_stdio(false);

這會禁用 C 和 C++ 標準流之間的同步.默認情況下,所有標準流都是同步的,這在實踐中允許您混合 C 和 C++ 風格的 I/O 并獲得合理和預期的結果.如果禁用同步,則允許 C++ 流擁有自己的獨立緩沖區,這使得混合 C 和 C++ 風格的 I/O 成為一種冒險.

This disables the synchronization between the C and C++ standard streams. By default, all standard streams are synchronized, which in practice allows you to mix C- and C++-style I/O and get sensible and expected results. If you disable the synchronization, then C++ streams are allowed to have their own independent buffers, which makes mixing C- and C++-style I/O an adventure.

還要記住,同步的 C++ 流是線程安全的(來自不同線程的輸出可能會交錯,但不會出現數據競爭).

Also keep in mind that synchronized C++ streams are thread-safe (output from different threads may interleave, but you get no data races).

cin.tie(NULL);

這將 cincout 分開.綁定流可確保在對另一個流進行每次 I/O 操作之前自動刷新一個流.

This unties cin from cout. Tied streams ensure that one stream is flushed automatically before each I/O operation on the other stream.

默認情況下,cin 綁定到 cout 以確保合理的用戶交互.例如:

By default cin is tied to cout to ensure a sensible user interaction. For example:

std::cout << "Enter name:";
std::cin >> name;

如果 cincout 是綁定的,你可以期待在程序提示用戶輸入之前輸出被刷新(即,在控制臺上可見).如果您解開流,程序可能會阻止等待用戶輸入他們的姓名,但輸入姓名"消息尚不可見(因為 cout 在默認情況下被緩沖,輸出被刷新/顯示在控制臺僅在需要時或緩沖區已滿時).

If cin and cout are tied, you can expect the output to be flushed (i.e., visible on the console) before the program prompts input from the user. If you untie the streams, the program might block waiting for the user to enter their name but the "Enter name" message is not yet visible (because cout is buffered by default, output is flushed/displayed on the console only on demand or when the buffer is full).

因此,如果您將 cincout 解開,則必須確保每次要在等待輸入之前顯示內容時手動刷新 coutcin 上.

So if you untie cin from cout, you must make sure to flush cout manually every time you want to display something before expecting input on cin.

總而言之,了解它們各自的作用,了解后果,然后決定您是否真的想要或需要速度提高的可能副作用.

In conclusion, know what each of them does, understand the consequences, and then decide if you really want or need the possible side effect of speed improvement.

這篇關于ios_base::sync_with_stdio(false) 的意義;cin.tie(NULL);的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Algorithm to convert RGB to HSV and HSV to RGB in range 0-255 for both(將 RGB 轉換為 HSV 并將 HSV 轉換為 RGB 的算法,范圍為 0-255)
How to convert an enum type variable to a string?(如何將枚舉類型變量轉換為字符串?)
When to use inline function and when not to use it?(什么時候使用內聯函數,什么時候不使用?)
Examples of good gotos in C or C++(C 或 C++ 中好的 goto 示例)
Is TCHAR still relevant?(TCHAR 仍然相關嗎?)
C99 stdint.h header and MS Visual Studio(C99 stdint.h 頭文件和 MS Visual Studio)
主站蜘蛛池模板: 帽子厂家_帽子工厂_帽子定做_义乌帽厂_帽厂_制帽厂 | 【星耀裂变】_企微SCRM_任务宝_视频号分销裂变_企业微信裂变增长_私域流量_裂变营销 | 丝杆升降机-不锈钢丝杆升降机-非标定制丝杆升降机厂家-山东鑫光减速机有限公司 | 世界箱包品牌十大排名,女包小众轻奢品牌推荐200元左右,男包十大奢侈品牌排行榜双肩,学生拉杆箱什么品牌好质量好 - Gouwu3.com | 巨野电机维修-水泵维修-巨野县飞宇机电维修有限公司 | 利浦顿蒸汽发生器厂家-电蒸汽发生器/燃气蒸汽发生器_湖北利浦顿热能科技有限公司官网 | 精密模具加工制造 - 富东懿 | BHK汞灯-百科|上海熙浩实业有限公司 | 网站优化公司_北京网站优化_抖音短视频代运营_抖音关键词seo优化排名-通则达网络 | 超声波乳化机-超声波分散机|仪-超声波萃取仪-超声波均质机-精浩机械|首页 | 焊锡丝|焊锡条|无铅锡条|无铅锡丝|无铅焊锡线|低温锡膏-深圳市川崎锡业科技有限公司 | GAST/BRIWATEC/CINCINNATI/KARL-KLEIN/ZIEHL-ABEGG风机|亚喜科技 | 导电银胶_LED封装导电银胶_半导体封装导电胶厂家-上海腾烁 | 广州二手电缆线回收,旧电缆回收,广州铜线回收-广东益福电缆线回收公司 | 户外-组合-幼儿园-不锈钢-儿童-滑滑梯-床-玩具-淘气堡-厂家-价格 | 交变/复合盐雾试验箱-高低温冲击试验箱_安奈设备产品供应杭州/江苏南京/安徽马鞍山合肥等全国各地 | 网架支座@球铰支座@钢结构支座@成品支座厂家@万向滑动支座_桥兴工程橡胶有限公司 | 北京中创汇安科贸有限公司| 广州工业氧气-工业氩气-工业氮气-二氧化碳-广州市番禺区得力气体经营部 | 钢骨架轻型板_膨石轻型板_钢骨架轻型板价格_恒道新材料 | EPK超声波测厚仪,德国EPK测厚仪维修-上海树信仪器仪表有限公司 | 浇钢砖,流钢砖_厂家价低-淄博恒森耐火材料有限公司 | 网站建设-高端品牌网站设计制作一站式定制_杭州APP/微信小程序开发运营-鼎易科技 | 葡萄酒灌装机-食用油灌装机-液体肥灌装设备厂家_青州惠联灌装机械 | 北京开源多邦科技发展有限公司官网| 南京雕塑制作厂家-不锈钢雕塑制作-玻璃钢雕塑制作-先登雕塑厂 | 硅胶制品-硅橡胶制品-东莞硅胶制品厂家-广东帝博科技有限公司 | 变色龙云 - 打包app_原生app_在线制作平台_短链接_ip查询 | 探伤仪,漆膜厚度测试仪,轮胎花纹深度尺厂家-淄博创宇电子 | 衡阳耐适防护科技有限公司——威仕盾焊接防护用品官网/焊工手套/焊接防护服/皮革防护手套 | 江苏密集柜_电动_手动_移动_盛隆柜业江苏档案密集柜厂家 | 东莞工厂厂房装修_无尘车间施工_钢结构工程安装-广东集景建筑装饰设计工程有限公司 | ET3000双钳形接地电阻测试仪_ZSR10A直流_SXJS-IV智能_SX-9000全自动油介质损耗测试仪-上海康登 | 深圳市八百通智能技术有限公司官方网站 | 艺术涂料_进口艺术涂料_艺术涂料加盟_艺术涂料十大品牌 -英国蒙太奇艺术涂料 | crm客户关系管理系统,销售管理系统,crm系统,在线crm,移动crm系统 - 爱客crm | 山东包装,山东印刷厂,济南印刷厂-济南富丽彩印刷有限公司 | 移动机器人产业联盟官网| 佛山商标注册_商标注册代理|专利注册申请_商标注册公司_鸿邦知识产权 | 无机纤维喷涂棉-喷涂棉施工工程-山东华泉建筑工程有限公司▲ | 威客电竞(vk·game)·电子竞技赛事官网 |