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

問題描述

包含的意義是什么

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)
主站蜘蛛池模板: 91精品国产日韩91久久久久久 | 精品熟人一区二区三区四区 | 一区二区播放 | 午夜影院在线观看免费 | 伊人超碰 | 爱爱视频网 | 精品福利av导航 | 91电影在线播放 | 亚洲国产一区视频 | 国产日韩欧美一区 | 久久精品国产一区二区三区 | 福利久久| 国产精品三级久久久久久电影 | 国产伦精品一区二区三区照片91 | 欧美成年人视频在线观看 | 国精产品一区二区三区 | 午夜国产 | 91久久精品 | 97精品超碰一区二区三区 | 国产1区在线 | 久久久久久久久久久久久久久久久久久久 | 日韩av手机在线观看 | 九九99靖品 | 视频二区在线观看 | 国产免费一二三区 | 999久久久久久久久 国产欧美在线观看 | 亚洲网站在线观看 | 欧美成人精品一区二区男人看 | www.av7788.com| 亚洲一区二区中文字幕 | 国产黄色一级片 | 午夜播放器在线观看 | 色视频在线播放 | 成人av电影在线 | 午夜在线 | 久久精品久久久久久 | 亚洲欧洲综合av | 日韩久久网 | 国产精品区二区三区日本 | 在线视频一区二区 | 日韩免费福利视频 |