<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://www.33dai.wiki/index.php?action=history&amp;feed=atom&amp;title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80%2F07-%E6%96%87%E4%BB%B6%E8%AF%BB%E5%86%99%E4%B8%8E%E9%AB%98%E7%BA%A7IO</id>
	<title>03-进阶基础/07-文件读写与高级IO - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://www.33dai.wiki/index.php?action=history&amp;feed=atom&amp;title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80%2F07-%E6%96%87%E4%BB%B6%E8%AF%BB%E5%86%99%E4%B8%8E%E9%AB%98%E7%BA%A7IO"/>
	<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80/07-%E6%96%87%E4%BB%B6%E8%AF%BB%E5%86%99%E4%B8%8E%E9%AB%98%E7%BA%A7IO&amp;action=history"/>
	<updated>2026-05-20T23:50:23Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80/07-%E6%96%87%E4%BB%B6%E8%AF%BB%E5%86%99%E4%B8%8E%E9%AB%98%E7%BA%A7IO&amp;diff=329&amp;oldid=prev</id>
		<title>33DAI：​导入1个版本</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80/07-%E6%96%87%E4%BB%B6%E8%AF%BB%E5%86%99%E4%B8%8E%E9%AB%98%E7%BA%A7IO&amp;diff=329&amp;oldid=prev"/>
		<updated>2026-05-20T18:12:09Z</updated>

		<summary type="html">&lt;p&gt;导入1个版本&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年5月20日 (三) 18:12的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;zh-Hans-CN&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;（没有差异）&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>33DAI</name></author>
	</entry>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80/07-%E6%96%87%E4%BB%B6%E8%AF%BB%E5%86%99%E4%B8%8E%E9%AB%98%E7%BA%A7IO&amp;diff=328&amp;oldid=prev</id>
		<title>-&gt;Importer：​批量导入三三文档</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80/07-%E6%96%87%E4%BB%B6%E8%AF%BB%E5%86%99%E4%B8%8E%E9%AB%98%E7%BA%A7IO&amp;diff=328&amp;oldid=prev"/>
		<updated>2026-05-20T16:50:33Z</updated>

		<summary type="html">&lt;p&gt;批量导入三三文档&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年5月20日 (三) 16:50的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;zh-Hans-CN&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;（没有差异）&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>-&gt;Importer</name></author>
	</entry>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80/07-%E6%96%87%E4%BB%B6%E8%AF%BB%E5%86%99%E4%B8%8E%E9%AB%98%E7%BA%A7IO&amp;diff=229&amp;oldid=prev</id>
		<title>33DAI：​导入1个版本</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80/07-%E6%96%87%E4%BB%B6%E8%AF%BB%E5%86%99%E4%B8%8E%E9%AB%98%E7%BA%A7IO&amp;diff=229&amp;oldid=prev"/>
		<updated>2026-05-20T16:25:22Z</updated>

		<summary type="html">&lt;p&gt;导入1个版本&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年5月20日 (三) 16:25的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;zh-Hans-CN&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;（没有差异）&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>33DAI</name></author>
	</entry>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80/07-%E6%96%87%E4%BB%B6%E8%AF%BB%E5%86%99%E4%B8%8E%E9%AB%98%E7%BA%A7IO&amp;diff=228&amp;oldid=prev</id>
		<title>-&gt;Importer：​批量导入三三文档</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=03-%E8%BF%9B%E9%98%B6%E5%9F%BA%E7%A1%80/07-%E6%96%87%E4%BB%B6%E8%AF%BB%E5%86%99%E4%B8%8E%E9%AB%98%E7%BA%A7IO&amp;diff=228&amp;oldid=prev"/>
		<updated>2026-05-20T16:22:29Z</updated>

		<summary type="html">&lt;p&gt;批量导入三三文档&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
== 文件输入输出（&amp;lt;code&amp;gt;freopen&amp;lt;/code&amp;gt;） ==&lt;br /&gt;
&lt;br /&gt;
NOI 系列赛事通常要求使用文件输入输出：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;bits/stdc++.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    freopen(&amp;quot;problem.in&amp;quot;, &amp;quot;r&amp;quot;, stdin);&lt;br /&gt;
    freopen(&amp;quot;problem.out&amp;quot;, &amp;quot;w&amp;quot;, stdout);&lt;br /&gt;
&lt;br /&gt;
    // 正常使用 cin / cout 即可&lt;br /&gt;
    int x;&lt;br /&gt;
    cin &amp;gt;&amp;gt; x;&lt;br /&gt;
    cout &amp;lt;&amp;lt; x * 2 &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- &amp;lt;code&amp;gt;&amp;quot;r&amp;quot;&amp;lt;/code&amp;gt;：read，读模式&lt;br /&gt;
- &amp;lt;code&amp;gt;&amp;quot;w&amp;quot;&amp;lt;/code&amp;gt;：write，写模式&lt;br /&gt;
- 文件名在正式比赛的试卷首页会给出&lt;br /&gt;
&lt;br /&gt;
== 输入输出加速 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
ios::sync_with_stdio(false);&lt;br /&gt;
cin.tie(0);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
加上这两行后，&amp;lt;code&amp;gt;cin&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;cout&amp;lt;/code&amp;gt; 的速度接近 &amp;lt;code&amp;gt;scanf&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;printf&amp;lt;/code&amp;gt;。&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;注意&amp;#039;&amp;#039;&amp;#039;：加速后不要混用 &amp;lt;code&amp;gt;cin&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;cout&amp;lt;/code&amp;gt; 和 &amp;lt;code&amp;gt;scanf&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;printf&amp;lt;/code&amp;gt;，否则会导致输出顺序混乱。&lt;br /&gt;
&lt;br /&gt;
== 读入到文件末尾 ==&lt;br /&gt;
&lt;br /&gt;
当题目没有告诉具体有多少输入时，读入到 EOF：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// 方法一&lt;br /&gt;
int x;&lt;br /&gt;
while (cin &amp;gt;&amp;gt; x)&lt;br /&gt;
{&lt;br /&gt;
    // 处理 x&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// 方法二（读取一行）&lt;br /&gt;
string s;&lt;br /&gt;
while (getline(cin, s))&lt;br /&gt;
{&lt;br /&gt;
    // 处理 s&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 保留小数位数 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
cout &amp;lt;&amp;lt; fixed &amp;lt;&amp;lt; setprecision(3) &amp;lt;&amp;lt; 1.0 / 3;&lt;br /&gt;
// 输出 0.333&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 完整加速框架 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;bits/stdc++.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    ios::sync_with_stdio(false);&lt;br /&gt;
    cin.tie(0);&lt;br /&gt;
&lt;br /&gt;
    // 你的代码&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 带文件 IO 的完整框架 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;bits/stdc++.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    ios::sync_with_stdio(false);&lt;br /&gt;
    cin.tie(0);&lt;br /&gt;
    freopen(&amp;quot;problem.in&amp;quot;, &amp;quot;r&amp;quot;, stdin);&lt;br /&gt;
    freopen(&amp;quot;problem.out&amp;quot;, &amp;quot;w&amp;quot;, stdout);&lt;br /&gt;
&lt;br /&gt;
    // 你的代码&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:进阶基础]]&lt;br /&gt;
[[Category:三三文档]]&lt;/div&gt;</summary>
		<author><name>-&gt;Importer</name></author>
	</entry>
</feed>