<?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%2F04-%E7%BB%93%E6%9E%84%E4%BD%93</id>
	<title>03-进阶基础/04-结构体 - 版本历史</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%2F04-%E7%BB%93%E6%9E%84%E4%BD%93"/>
	<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/04-%E7%BB%93%E6%9E%84%E4%BD%93&amp;action=history"/>
	<updated>2026-05-21T02:30:56Z</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/04-%E7%BB%93%E6%9E%84%E4%BD%93&amp;diff=323&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/04-%E7%BB%93%E6%9E%84%E4%BD%93&amp;diff=323&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;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&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;4&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;!-- diff cache key my_wiki:diff:1.41:old-322:rev-323 --&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/04-%E7%BB%93%E6%9E%84%E4%BD%93&amp;diff=322&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/04-%E7%BB%93%E6%9E%84%E4%BD%93&amp;diff=322&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;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&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;4&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;!-- diff cache key my_wiki:diff:1.41:old-223:rev-322 --&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/04-%E7%BB%93%E6%9E%84%E4%BD%93&amp;diff=223&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/04-%E7%BB%93%E6%9E%84%E4%BD%93&amp;diff=223&amp;oldid=prev"/>
		<updated>2026-05-20T16:25:19Z</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;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&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;4&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;!-- diff cache key my_wiki:diff:1.41:old-222:rev-223 --&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/04-%E7%BB%93%E6%9E%84%E4%BD%93&amp;diff=222&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/04-%E7%BB%93%E6%9E%84%E4%BD%93&amp;diff=222&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;
== 结构体 ==&lt;br /&gt;
&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;
struct Student&lt;br /&gt;
{&lt;br /&gt;
    string name;&lt;br /&gt;
    int age;&lt;br /&gt;
    double score;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&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;
Student s1;              // 创建一个 Student 类型的变量&lt;br /&gt;
s1.name = &amp;quot;张三&amp;quot;;&lt;br /&gt;
s1.age = 18;&lt;br /&gt;
s1.score = 95.5;&lt;br /&gt;
&lt;br /&gt;
Student s2 = {&amp;quot;李四&amp;quot;, 17, 88.0}; // 初始化列表&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 结构体访问成员 ===&lt;br /&gt;
&lt;br /&gt;
使用 &amp;lt;code&amp;gt;.&amp;lt;/code&amp;gt; 运算符访问成员：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
cout &amp;lt;&amp;lt; s1.name &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; s1.score;&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;
Student a[100];&lt;br /&gt;
a[0].name = &amp;quot;王五&amp;quot;;&lt;br /&gt;
a[0].age = 19;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&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;
struct Student&lt;br /&gt;
{&lt;br /&gt;
    string name;&lt;br /&gt;
    int score;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
bool cmp(const Student &amp;amp;a, const Student &amp;amp;b)&lt;br /&gt;
{&lt;br /&gt;
    return a.score &amp;gt; b.score; // 按分数从高到低&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// 使用&lt;br /&gt;
vector&amp;lt;Student&amp;gt; s(n);&lt;br /&gt;
sort(s.begin(), s.end(), cmp);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 方法二：重载 &amp;lt;code&amp;gt;&amp;lt;&amp;lt;/code&amp;gt; 运算符 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
struct Student&lt;br /&gt;
{&lt;br /&gt;
    string name;&lt;br /&gt;
    int score;&lt;br /&gt;
    bool operator&amp;lt;(const Student &amp;amp;b) const&lt;br /&gt;
    {&lt;br /&gt;
        return score &amp;gt; b.score; // 按分数从高到低&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// 使用：可以直接 sort，不需要 cmp 参数&lt;br /&gt;
sort(s.begin(), s.end());&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 结构体与 &amp;lt;code&amp;gt;typedef&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;using&amp;lt;/code&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
typedef long long ll;&lt;br /&gt;
// 等价于&lt;br /&gt;
using ll = long long;&lt;br /&gt;
&lt;br /&gt;
struct Point { int x, y; };&lt;br /&gt;
using P = Point; // 给类型起别名&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;
struct Point { int x, y; };&lt;br /&gt;
struct Rectangle&lt;br /&gt;
{&lt;br /&gt;
    Point topLeft;&lt;br /&gt;
    Point bottomRight;&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>