-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a93216f
Showing
13 changed files
with
8,681 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,364 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "c542536e", | ||
"metadata": {}, | ||
"source": [ | ||
"## 如何编译\n", | ||
"\n", | ||
"linux的编译命令如下\n", | ||
"\n", | ||
"```\n", | ||
"g++ spiffy.cxx\n", | ||
"\n", | ||
"# 如果需要链接c++库\n", | ||
"g++ spiffy.cxx -lg++\n", | ||
"# 如果要编译多个源文件\n", | ||
"g++ my.cxx precious.cxx\n", | ||
"# 这将生成一个名为a.out的可执行文件和两个目标代码文件my.o和\n", | ||
"precious.o。如果接下来修改了其中的某个源代码文件,如mu.cxx,则可\n", | ||
"以使用my.cxx和precious.o来重新编译:\n", | ||
"g++ my.cxx precious.o\n", | ||
"```\n", | ||
"\n", | ||
"## 2.1 进入C++" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"id": "c253c5aa", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"这个是c++\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"// 这个是一个最简单的程序\n", | ||
"#include <iostream>\n", | ||
"int main(){\n", | ||
" using namespace std;\n", | ||
" cout<<\"这个是c++\"<<endl;\n", | ||
" return 0;\n", | ||
"}\n", | ||
"main();" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "cedc3261", | ||
"metadata": {}, | ||
"source": [ | ||
"一般情况下,程序里必须要使用main函数来作为入口函数" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"id": "e1ea7557", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"// c++的注释\n", | ||
"/*注释*/" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"id": "3be3508d", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"// include是编译指令,表示我们引入一些内容\n", | ||
"#include <iostream>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 19, | ||
"id": "5de02721", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"不使用命名空间\n", | ||
"使用命名空间" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"// namespace表示命名空间,主要用于区分不同模块\n", | ||
"using namespace std;\n", | ||
"std::cout<<\"不使用命名空间\"<<endl;\n", | ||
"cout<<\"使用命名空间\";" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 20, | ||
"id": "41639903", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"测试" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"// 也可以只使用某一个\n", | ||
"using std::cout;\n", | ||
"cout<<\"测试\";" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 21, | ||
"id": "13e42e18", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"你好\n", | ||
"世界" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"// endl表示换行符\n", | ||
"cout<<\"你好\"<<endl<<\"世界\";" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 23, | ||
"id": "ae4d1057", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"你好\n", | ||
"世界" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"// 也可以使用\\n\n", | ||
"cout<<\"你好\\n世界\";" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "01a54628", | ||
"metadata": {}, | ||
"source": [ | ||
"## 2.2 C++语句" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 26, | ||
"id": "f23b63b7", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"// 声明一个变量\n", | ||
"int a;" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 28, | ||
"id": "3c2ec0b0", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"64" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"// 变量赋值\n", | ||
"a = 64;\n", | ||
"cout<<a;" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 30, | ||
"id": "026b9a61", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"888888" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"// 也可以连续赋值\n", | ||
"int a;\n", | ||
"int b;\n", | ||
"int c;\n", | ||
"a=b=c=88;\n", | ||
"cout<<a<<b<<c;" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "c1058390", | ||
"metadata": {}, | ||
"source": [ | ||
"## 2.3 其他c++语句" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 33, | ||
"id": "d86e5154", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"输入一个值456\n", | ||
"你输入的值为456" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"// 使用cin来输入\n", | ||
"int a;\n", | ||
"cout << \"输入一个值\";\n", | ||
"cin >> a;\n", | ||
"cout << \"你输入的值为\"<<a;" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 35, | ||
"id": "d0f08a43", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"abcd" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"// cout可以这样\n", | ||
"cout << \"a\"\n", | ||
" <<\"b\"\n", | ||
" <<\"c\"\n", | ||
" <<\"d\";" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d7a9fd0f", | ||
"metadata": {}, | ||
"source": [ | ||
"## 2.4函数" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "16f5b9d4", | ||
"metadata": {}, | ||
"source": [ | ||
"#include <cmath>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 61, | ||
"id": "bc2b8ae5", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"praram:456" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"// 自定义函数\n", | ||
"void simon(int n){\n", | ||
" cout<<\"praram:\"<<n;\n", | ||
"}\n", | ||
"simon(456);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 62, | ||
"id": "15460b0a", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"100" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"int testReturn(int a){\n", | ||
" return a*10;\n", | ||
"}\n", | ||
"cout<<testReturn(10);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "375203ea", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "C++17", | ||
"language": "C++17", | ||
"name": "xcpp17" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": "text/x-c++src", | ||
"file_extension": ".cpp", | ||
"mimetype": "text/x-c++src", | ||
"name": "c++", | ||
"version": "17" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.