久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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);的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

包含的意義是什么

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

在 C++ 程序中?

在我的測試中,它加快了執(zhí)行時間,但是否有我應(yīng)該擔(dān)心的測試用例包含這個?

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)?

此外,如果其值已設(shè)置為 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

以上代碼運(yùn)行良好,直到我在 C++ 程序中使用 scanf/printf 并將值設(shè)為 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?

推薦答案

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

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++ 標(biāo)準(zhǔn)流之間的同步.默認(rèn)情況下,所有標(biāo)準(zhǔn)流都是同步的,這在實踐中允許您混合 C 和 C++ 風(fēng)格的 I/O 并獲得合理和預(yù)期的結(jié)果.如果禁用同步,則允許 C++ 流擁有自己的獨(dú)立緩沖區(qū),這使得混合 C 和 C++ 風(fēng)格的 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++ 流是線程安全的(來自不同線程的輸出可能會交錯,但不會出現(xiàn)數(shù)據(jù)競爭).

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 分開.綁定流可確保在對另一個流進(jìn)行每次 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.

默認(rèn)情況下,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 在默認(rèn)情況下被緩沖,輸出被刷新/顯示在控制臺僅在需要時或緩沖區(qū)已滿時).

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 解開,則必須確保每次要在等待輸入之前顯示內(nèi)容時手動刷新 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.

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

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

相關(guān)文檔推薦

Algorithm to convert RGB to HSV and HSV to RGB in range 0-255 for both(將 RGB 轉(zhuǎn)換為 HSV 并將 HSV 轉(zhuǎn)換為 RGB 的算法,范圍為 0-255)
How to convert an enum type variable to a string?(如何將枚舉類型變量轉(zhuǎn)換為字符串?)
When to use inline function and when not to use it?(什么時候使用內(nèi)聯(lián)函數(shù),什么時候不使用?)
Examples of good gotos in C or C++(C 或 C++ 中好的 goto 示例)
Is TCHAR still relevant?(TCHAR 仍然相關(guān)嗎?)
C99 stdint.h header and MS Visual Studio(C99 stdint.h 頭文件和 MS Visual Studio)
主站蜘蛛池模板: 在线色网站 | 五月婷婷六月天 | 亚洲国产日韩在线 | 国产在线观看网站 | 欧美久久视频 | 国产香蕉在线观看 | 欧美夜夜操 | 性视频网 | 国产伦理一区二区 | 永久免费视频 | 成人网在线观看 | 久久久久久亚洲精品 | 欧美成人久久 | 伊人影院综合 | 美日韩精品| 亚洲免费专区 | 精品久久久久久久久久久 | 久久网av| 亚洲免费视频网站 | www久久久久 | 黄色av日韩 | 国产日韩视频 | 午夜激情福利视频 | 日本不卡视频在线观看 | 国产中文字幕在线 | 欧美一区二区三区在线 | 国产一级一片免费播放放a 男男成人高潮片免费网站 精品视频在线观看 | 手机在线毛片 | 哦┅┅快┅┅用力啊┅aps | 天天曰天天操 | 亚洲精品黄 | 天天操夜夜摸 | 私库av在线 | 青青青草视频 | 欧美精品日韩少妇 | 日韩三级精品 | 91久久久久久久 | 国产美女精品视频 | 欧美在线视频免费 | 午夜美女福利视频 | 日韩精品影院 |