Ver código fonte

C/C++零基础入门 系列教程 不懂英文 从零开始

hongwenjun 1 ano atrás
pai
commit
30457fabbf
51 arquivos alterados com 1380 adições e 0 exclusões
  1. 26 0
      01.mysort.cpp
  2. 19 0
      README.md
  3. 7 0
      examples/01_helloworld.c
  4. 10 0
      examples/02_textinput.c
  5. 14 0
      examples/03_simplemath.c
  6. 36 0
      examples/04_quadsolve.c
  7. 11 0
      examples/05_factorial.c
  8. 18 0
      examples/06_invfactorial.c
  9. 17 0
      examples/07_gcd.c
  10. 26 0
      examples/08_pointdist.c
  11. 35 0
      examples/09_debugmacro.c
  12. 21 0
      examples/10_malloc.c
  13. 23 0
      examples/11_strings.c
  14. 9 0
      examples/12_helloworld.cpp
  15. 24 0
      examples/13_square.cpp
  16. 35 0
      examples/14_rectangle.cpp
  17. 30 0
      examples/15_vectors.cpp
  18. 18 0
      examples/16_max.cpp
  19. 35 0
      examples/17_divby0.cpp
  20. 58 0
      examples/18_casts.cpp
  21. 30 0
      examples/19_rtti.cpp
  22. 16 0
      examples/20_stltextinput.cpp
  23. 24 0
      examples/21_fibonacci.cpp
  24. 57 0
      examples/22_kvdb.cpp
  25. 16 0
      examples/23_randomcpp11.cpp
  26. 14 0
      examples/24_regexcpp11.cpp
  27. 25 0
      examples/25_threadcpp11.cpp
  28. 28 0
      examples/26_listdircpp17.cpp
  29. 15 0
      examples/27_helloworld.cpp
  30. 50 0
      examples/28_matmult.cpp
  31. 27 0
      examples/29_pointinpoly.cpp
  32. 35 0
      examples/30_gauss.cpp
  33. 14 0
      examples/31_regex.cpp
  34. 25 0
      examples/32_thread.cpp
  35. 29 0
      examples/33_listdir.cpp
  36. 15 0
      examples/34_add.c
  37. 13 0
      examples/35_longfactorial.c
  38. 15 0
      examples/36_cppbindings.cpp
  39. 28 0
      examples/37_compute_e.c
  40. 27 0
      examples/38_euler_formula.c
  41. 15 0
      examples/39_hellosqlite.c
  42. 27 0
      examples/40_insandsel.c
  43. 74 0
      examples/41_kvdb.c
  44. 15 0
      examples/42_helloncurses.c
  45. 23 0
      examples/43_colors.c
  46. 36 0
      examples/44_cursorctl.c
  47. 61 0
      examples/45_fire.c
  48. 22 0
      examples/46_getexample.c
  49. 25 0
      examples/47_postexample.c
  50. 36 0
      examples/48_sslexample.c
  51. 71 0
      settings.json

+ 26 - 0
01.mysort.cpp

@@ -0,0 +1,26 @@
+#include <algorithm>
+#include <stdio.h>
+#define SIZEOF(T) (sizeof(T)) / (sizeof(T[0]))
+void print_arr(int *arr, int n);
+
+void bubbleSort(int *arr, int n) {
+  for (int i = 0; i < n - 1; i++)
+    for (int j = 0; j < n - i - 1; j++)
+      if (arr[j] > arr[j + 1])
+        std::swap(arr[j], arr[j + 1]);
+}
+
+int main() {
+  int arr[] = {9, 2, 5, 7, 3, 1, 8, 4, 6};
+  int n = SIZEOF(arr);
+  bubbleSort(arr, n);
+  print_arr(arr, n);
+  return 0;
+}
+
+void print_arr(int *arr, int n) {
+  printf("排序结果\n");
+  for (int i = 0; i != n; i++) {
+    printf("%d ", arr[i]);
+  }
+}

+ 19 - 0
README.md

@@ -1,2 +1,21 @@
 # cpp
 C/C++零基础入门 系列教程 不懂英文 从零开始
+
+### github源码:  https://github.com/hongwenjun/cpp
+## [【C/CPP零基础入门_Part01_排序算法 冒泡排序】](https://b23.tv/CCcx3mX)
+### https://b23.tv/CCcx3mX
+
+## 简介
+### C/C++零基础入门: 不懂英文 从零开始
+- 学习C/C++编程对于零基础的人来说可能会有一些挑战,但是掌握这门语言将会为你打开许多机会。
+- 本系列教程会分享一些学习的工具和资源,只要对照视频开始学习C/C++,就可以了解基本的语法和概念,
+比如变量、数据类型、条件语句和循环结构等。
+
+[![](https://lyvba.com/wp-content/uploads/2023/09/C_CPP零基础入门.jpg)](https://www.bilibili.com/video/BV1D8411y7ya)
+
+### C/CPP零基础入门编程软件资源
+https://wwcz.lanzout.com/b01urh63a   密码:7q5c
+
+- `算法动画图解_中文欢乐版.apk`  视频右侧的 算法动画图解 程序
+- `MSVC2015Mini.7z`    视频中 VSCODE 调用的 C/C++ 编译器
+

+ 7 - 0
examples/01_helloworld.c

@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main()
+{
+	printf("Hello, world!\n");
+	return 0;
+}

+ 10 - 0
examples/02_textinput.c

@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+int main()
+{
+	char name[1024];
+	printf("What is your name?\n");
+	scanf("%s", name);
+	printf("Hello, %s!\n", name);
+	return 0;
+}

+ 14 - 0
examples/03_simplemath.c

@@ -0,0 +1,14 @@
+#include <math.h>
+#include <stdio.h>
+
+int main()
+{
+	int n1, n2;
+	n1 = 1;
+	n2 = 2;
+	printf("%d + %d = %d\n", n1, n2, n1 + n2);
+	int n3;
+	n3 = 4;
+	printf("Square root of %d is %f\n", n3, sqrt(n3));
+	return 0;
+}

+ 36 - 0
examples/04_quadsolve.c

@@ -0,0 +1,36 @@
+#include <math.h>
+#include <stdio.h>
+
+int solvequadeq(double a, double b, double c, double *x1, double *x2)
+{
+	double D = pow(b, 2) - 4 * a * c;
+	if (D < 0)
+		return 0;
+	if (D == 0)
+	{
+		*x1 = (-b) / (2 * a);
+		return 1;
+	}
+	else
+	{
+		*x1 = (-b - sqrt(D)) / (2 * a);
+		*x2 = (-b + sqrt(D)) / (2 * a);
+		return 2;
+	}
+}
+
+int main()
+{
+	double a = 1;
+	double b = -4;
+	double c = 3;
+	printf("Equation: %f*x^2 + %f*x + %f = 0\n", a, b, c);
+	double x1, x2;
+	int r = solvequadeq(a, b, c, &x1, &x2);
+	printf("%d solution(s) found\n", r);
+	if (r > 0)
+		printf("x1 = %f\n", x1);
+	if (r > 1)
+		printf("x2 = %f\n", x2);
+	return 0;
+}

+ 11 - 0
examples/05_factorial.c

@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+int main()
+{
+	int n = 10;
+	int factorial = 1;
+	for (int i = 1; i <= n; i++)
+		factorial *= i;
+	printf("Factorial of %d is %d\n", n, factorial);
+	return 0;
+}

+ 18 - 0
examples/06_invfactorial.c

@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+int main()
+{
+	int factorial = 3628800;
+	int n = 1;
+	int tmpfact = 1;
+	while (tmpfact < factorial)
+	{
+		tmpfact *= n;
+		n++;
+	}
+	if (tmpfact == factorial)
+		printf("%d is a factorial of %d\n", factorial, n - 1);
+	else
+		printf("%d is not a factorial\n", factorial);
+	return 0;
+}

+ 17 - 0
examples/07_gcd.c

@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+int gcd(int a, int b)
+{
+	if (b == 0)
+		return a;
+	else
+		return gcd(b, a % b);
+}
+
+int main()
+{
+	int a = 10;
+	int b = 15;
+	printf("Greatest common divisor of %d and %d is %d\n", a, b, gcd(a, b));
+	return 0;
+}

+ 26 - 0
examples/08_pointdist.c

@@ -0,0 +1,26 @@
+#include <math.h>
+#include <stdio.h>
+
+struct Point
+{
+	int x;
+	int y;
+};
+
+double dist(struct Point *a, struct Point *b)
+{
+	return sqrt(pow(a->x - b->x, 2) + pow(a->y - b->y, 2));
+}
+
+int main()
+{
+	struct Point p1;
+	struct Point p2;
+	p1.x = 1;
+	p1.y = 0;
+	p2.x = 0;
+	p2.y = 1;
+	printf("Distance between points [%d, %d] and [%d, %d] is %f\n", p1.x, p1.y,
+		   p2.x, p2.y, dist(&p1, &p2));
+	return 0;
+}

+ 35 - 0
examples/09_debugmacro.c

@@ -0,0 +1,35 @@
+#include <stdio.h>
+
+#define IS_DEBUG
+#define printnum(x) printf("%d\n", x)
+#ifdef IS_DEBUG
+#define readnum(x)                                  \
+	{                                               \
+		printf("Reading number with scanf(%%d)\n"); \
+		scanf("%d", &x);                            \
+	}
+#else
+#define readnum(x) scanf("%d", &x)
+#endif
+
+#if defined(IS_DEBUG) && !defined(debuginit)
+void debuginit()
+{
+	printf("Running in debug mode, disable this by commenting out #define "
+		   "IS_DEBUG\n");
+}
+#endif
+
+int main()
+{
+#ifdef IS_DEBUG
+	debuginit();
+#endif
+
+	printf("Enter some number:\n");
+	int x;
+	readnum(x);
+	printf("Number was ");
+	printnum(x);
+	return 0;
+}

+ 21 - 0
examples/10_malloc.c

@@ -0,0 +1,21 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main()
+{
+	char *mem;
+	mem = (char *)malloc(16);
+	memset(mem, 'A', 15);
+	mem[15] = 0;
+	printf("Dynamically allocated memory at %p\n", mem);
+	printf("Content: %s\n", mem);
+	mem = (char *)realloc(mem, 32);
+	memset(mem, 'A', 31);
+	mem[31] = 0;
+	printf("Reallocated, new address is %p\n", mem);
+	printf("Content: %s\n", mem);
+	free(mem);
+	printf("Freed memory at %p\n", mem);
+	return 0;
+}

+ 23 - 0
examples/11_strings.c

@@ -0,0 +1,23 @@
+#include <stdio.h>
+#include <string.h>
+
+int main()
+{
+	char str1[32];
+	char str2[32];
+
+	strcpy(str1, "String 1");
+	strcpy(str2, "String 2");
+
+	printf("String values are \"%s\" \"%s\"\n", str1, str2);
+	int diff = strcmp(str1, str2);
+	printf("First string is %s than second\n", (diff == 1 ? "bigger" : "less"));
+	char str3[32];
+	strcpy(str3, str1);
+	strcat(str3, str2);
+	printf("Concatenation of two strings is \"%s\"\n", str3);
+	int ingpos = strstr(str3, "ing") - str3;
+	printf("First occurrence of word ing in \"%s\" is at position %d\n", str3,
+		   ingpos);
+	return 0;
+}

+ 9 - 0
examples/12_helloworld.cpp

@@ -0,0 +1,9 @@
+#include <iostream>
+
+using namespace std;
+
+int main()
+{
+	cout << "Hello, world!" << endl;
+	return 0;
+}

+ 24 - 0
examples/13_square.cpp

@@ -0,0 +1,24 @@
+#include <iostream>
+
+using namespace std;
+
+class Square
+{
+	int size;
+
+  public:
+	void set_size(int s);
+	int get_size();
+	int area() { return size * size; }
+};
+
+void Square::set_size(int s) { size = s; }
+int Square::get_size() { return size; }
+int main()
+{
+	Square x;
+	x.set_size(10);
+	cout << "Area of square with side length " << x.get_size() << " is "
+		 << x.area() << endl;
+	return 0;
+}

+ 35 - 0
examples/14_rectangle.cpp

@@ -0,0 +1,35 @@
+#include <iostream>
+
+using namespace std;
+
+class Poly
+{
+  protected:
+	int width;
+	int height;
+
+  public:
+	Poly(int w, int h) { set_size(w, h); }
+	void set_size(int w, int h)
+	{
+		width = w;
+		height = h;
+	}
+	int get_width() { return width; }
+	int get_height() { return height; }
+};
+
+class Rectangle : public Poly
+{
+  public:
+	Rectangle(int w, int h) : Poly(w, h) {}
+	int area() { return width * height; }
+};
+
+int main()
+{
+	Rectangle x(10, 20);
+	cout << "Area of rectangle with sides length " << x.get_width() << " and "
+		 << x.get_height() << " is " << x.area() << endl;
+	return 0;
+}

+ 30 - 0
examples/15_vectors.cpp

@@ -0,0 +1,30 @@
+#include <iostream>
+
+using namespace std;
+
+class Vector
+{
+  public:
+	int x;
+	int y;
+	Vector(int x, int y) : x(x), y(y) {}
+	Vector operator+(const Vector &right)
+	{
+		Vector result(x + right.x, y + right.y);
+		return result;
+	}
+};
+
+std::ostream &operator<<(std::ostream &Str, Vector const &v)
+{
+	Str << "[" << v.x << "," << v.y << "]";
+	return Str;
+}
+
+int main()
+{
+	Vector x(2, 3);
+	Vector y(4, 5);
+	cout << "Sum of vectors " << x << " and " << y << " is " << x + y << endl;
+	return 0;
+}

+ 18 - 0
examples/16_max.cpp

@@ -0,0 +1,18 @@
+#include <iostream>
+
+using namespace std;
+
+template <typename T>
+T Max(T a, T b) { return (a > b) ? a : b; }
+int main()
+{
+	int a, b;
+	double c, d;
+	a = 2;
+	b = 7;
+	c = 3.5;
+	d = 10.25;
+	cout << "Maximum of " << a << " and " << b << " is " << Max(a, b) << endl;
+	cout << "Maximum of " << c << " and " << d << " is " << Max(c, d) << endl;
+	return 0;
+}

+ 35 - 0
examples/17_divby0.cpp

@@ -0,0 +1,35 @@
+#include <exception>
+#include <iostream>
+
+using namespace std;
+
+class divby0 : public exception
+{
+	const char *what() const throw() { return "Cannot divide by 0"; }
+};
+
+int divide(int a, int b)
+{
+	if (b == 0)
+		throw divby0();
+	return a / b;
+}
+
+int main()
+{
+	try
+	{
+		int a = 10;
+		int b = 5;
+		int c = 0;
+		int d = 1;
+		cout << a << " / " << b << " = " << divide(a, b) << endl;
+		cout << a << " / " << c << " = " << divide(a, c) << endl;
+		cout << a << " / " << d << " = " << divide(a, d) << endl;
+	}
+	catch (std::exception &e)
+	{
+		cout << e.what() << endl;
+	}
+	return 0;
+}

+ 58 - 0
examples/18_casts.cpp

@@ -0,0 +1,58 @@
+#include <iostream>
+
+using namespace std;
+
+class Base
+{
+	virtual void dummy()
+	{
+		// Required to make class polymorphic
+	}
+	// Some base class
+};
+
+class Derived : public Base
+{
+	// Some derived class
+};
+
+int main()
+{
+	Base *base = new Base;
+	Base *derived = new Derived;
+	Derived *tmp;
+
+	tmp = dynamic_cast<Derived *>(base);
+	if (tmp)
+		cout << "Base* has been successfully casted to Derived* using dynamic_cast"
+			 << endl;
+	else
+		cout << "dynamic_cast prevented Base* cast to Derived* from happening"
+			 << endl;
+
+	tmp = dynamic_cast<Derived *>(derived);
+	if (tmp)
+		cout << "Derived* has been successfully casted to Derived* using "
+				"dynamic_cast"
+			 << endl;
+	else
+		cout << "dynamic_cast prevented Derived* cast to Derived* from happening"
+			 << endl;
+
+	tmp = static_cast<Derived *>(base);
+	if (tmp)
+		cout << "Base* has been successfully casted to Derived* using static_cast"
+			 << endl;
+	else
+		cout << "This actually never happens" << endl;
+
+	tmp = static_cast<Derived *>(derived);
+	if (tmp)
+		cout
+			<< "Derived* has been successfully casted to Derived* using static_cast"
+			<< endl;
+	else
+		cout << "This actually never happens" << endl;
+
+	return 0;
+}

+ 30 - 0
examples/19_rtti.cpp

@@ -0,0 +1,30 @@
+#include <iostream>
+#include <typeinfo>
+
+using namespace std;
+
+class Base
+{
+	virtual void dummy()
+	{
+		// Required to make class polymorphic
+	}
+	// Some base class
+};
+
+class Derived : public Base
+{
+	// Some derived class
+};
+
+int main()
+{
+	Base *base = new Base;
+	Base *derived = new Derived;
+
+	// These outputs are implementation-dependent and may need to be demangled
+	cout << "Type of base variable is " << typeid(*base).name() << endl;
+	cout << "Type of derived variable is " << typeid(*derived).name() << endl;
+
+	return 0;
+}

+ 16 - 0
examples/20_stltextinput.cpp

@@ -0,0 +1,16 @@
+#include <iostream>
+#include <string>
+
+using namespace std;
+
+int main()
+{
+	string str;
+	cout << "Enter some string:" << endl;
+	getline(cin, str);
+	cout << "Entered string is: \"" << str << "\"" << endl;
+	cout << "Its length is " << str.size() << endl;
+	string str2 = str + str;
+	cout << "Doubled input string is \"" << str2 << "\"" << endl;
+	return 0;
+}

+ 24 - 0
examples/21_fibonacci.cpp

@@ -0,0 +1,24 @@
+#include <iostream>
+#include <vector>
+
+using namespace std;
+
+#define COUNT 15
+
+int main()
+{
+	vector<int> F;
+	F.push_back(1); // F(1) = 1
+	F.push_back(1); // F(2) = 1
+	for (int i = 2; i < COUNT; i++)
+	{
+		F.push_back(*(F.end() - 1) + *(F.end() - 2)); // F(x) = F(x-1) +
+													  // F(x-2)
+	}
+
+	cout << "Fibonacci numbers are:" << endl;
+	for (int i = 0; i < F.size(); i++)
+		cout << F[i] << ' ';
+
+	return 0;
+}

+ 57 - 0
examples/22_kvdb.cpp

@@ -0,0 +1,57 @@
+#include <iostream>
+#include <map>
+#include <string>
+
+using namespace std;
+
+int main()
+{
+	map<string, string> db;
+	cout << "Welcome to the simplest key-value database" << endl;
+	while (1)
+	{
+		cout << "What do you want to do?" << endl;
+		cout << "Enter P to [P]ut, G to [G]et or L to [L]ist" << endl;
+		cout << "Or enter Q to [Q]uit" << endl;
+		string action;
+		getline(cin, action);
+		if (action == "P")
+		{
+			string key;
+			string data;
+			cout << "Enter key: ";
+			getline(cin, key);
+			cout << "Enter data: ";
+			getline(cin, data);
+			db[key] = data;
+		}
+		if (action == "G")
+		{
+			cout << "Enter key: ";
+			string key;
+			getline(cin, key);
+			if (db.find(key) != db.end())
+			{
+				cout << "Your data: " << db[key] << endl;
+			}
+			else
+				cout << "No such key" << endl;
+		}
+		if (action == "L")
+		{
+			cout << "DB contents:" << endl;
+			for (auto it = db.begin(); it != db.end(); it++)
+			{
+				cout << it->first << ": " << it->second << endl;
+			}
+		}
+		if (action == "Q")
+		{
+			cout << "Bye" << endl;
+			break;
+		}
+		cout << endl;
+	}
+
+	return 0;
+}

+ 16 - 0
examples/23_randomcpp11.cpp

@@ -0,0 +1,16 @@
+#include <iostream>
+#include <random>
+
+using namespace std;
+
+int main()
+{
+	random_device rd;
+	mt19937 rng(rd());
+	uniform_real_distribution<double> dist(0.0, 2.0);
+	cout << "Generating 5 random numbers in [0.0; 2.0) range" << endl;
+	for (int i = 0; i < 5; i++)
+		cout << dist(rng) << " ";
+	cout << endl;
+	return 0;
+}

+ 14 - 0
examples/24_regexcpp11.cpp

@@ -0,0 +1,14 @@
+#include <iostream>
+#include <regex>
+#include <string>
+
+using namespace std;
+
+int main()
+{
+	string s = "Hello, world!";
+	regex expr("(\\w+),\\s(\\w+)!");
+	string fmt("$1, C++11!");
+	cout << regex_replace(s, expr, fmt) << endl;
+	return 0;
+}

+ 25 - 0
examples/25_threadcpp11.cpp

@@ -0,0 +1,25 @@
+#include <cstdlib>
+#include <ctime>
+#include <iostream>
+#include <thread>
+#include <unistd.h>
+
+using namespace std;
+
+void threadfunc(int x)
+{
+	usleep(rand() % 100000);
+	cout << "Hello, C++11 (id: " << x << ")" << endl;
+}
+
+int main()
+{
+	srand(time(0));
+
+	thread t1(&threadfunc, 1);
+	thread t2(&threadfunc, 2);
+
+	t1.join();
+	t2.join();
+	return 0;
+}

+ 28 - 0
examples/26_listdircpp17.cpp

@@ -0,0 +1,28 @@
+#include <iostream>
+#include <filesystem>
+
+using namespace std;
+using namespace std::filesystem;
+
+int main()
+{
+	path p("/sdcard");
+
+	if (!exists(p))
+	{
+		cout << p << " not found" << endl;
+		return 1;
+	}
+
+	if (!is_directory(p))
+	{
+		cout << p << " is not a directory" << endl;
+		return 1;
+	}
+
+	for (auto &d : directory_iterator(p))
+	{
+		cout << d.path() << endl;
+	}
+	return 0;
+}

+ 15 - 0
examples/27_helloworld.cpp

@@ -0,0 +1,15 @@
+#include <boost/algorithm/string.hpp>
+#include <iostream>
+#include <string>
+
+using namespace boost::algorithm;
+using namespace std;
+
+int main()
+{
+	string hwmod = "  Hell0, w0rld!  ";
+	string tmp = replace_all_copy(hwmod, "0", "o");
+	tmp = trim_copy(tmp);
+	cout << tmp << endl;
+	return 0;
+}

+ 50 - 0
examples/28_matmult.cpp

@@ -0,0 +1,50 @@
+#include <boost/numeric/ublas/matrix.hpp>
+#include <iomanip>
+#include <iostream>
+
+using namespace boost::numeric::ublas;
+using namespace std;
+
+// A custom, more pretty way to print matrices
+std::ostream &operator<<(std::ostream &Str, matrix<double> const &v)
+{
+	for (int i = 0; i < v.size1(); i++)
+	{
+		Str << ((i == 0) ? "[[" : " [");
+		for (int j = 0; j < v.size2(); j++)
+		{
+			Str << setw(4);
+			Str << v(i, j);
+			Str << setw(0);
+		}
+		Str << ((i == v.size1() - 1) ? "]]" : "]");
+		if (i != v.size1() - 1)
+			Str << endl;
+	}
+	return Str;
+}
+
+int main()
+{
+	matrix<double> A(2, 2);
+	A(0, 0) = 1;
+	A(0, 1) = 2;
+	A(1, 0) = 3;
+	A(1, 1) = 4;
+
+	matrix<double> B(2, 2);
+	B(0, 0) = -1;
+	B(0, 1) = 0;
+	B(1, 0) = 0;
+	B(1, 1) = -1;
+
+	matrix<double> C = prod(A, B);
+
+	cout << "Multiplication of " << endl
+		 << A << endl;
+	cout << "and " << endl
+		 << B << endl;
+	cout << "is" << endl;
+	cout << C << endl;
+	return 0;
+}

+ 27 - 0
examples/29_pointinpoly.cpp

@@ -0,0 +1,27 @@
+#include <boost/geometry.hpp>
+#include <boost/geometry/geometries/point_xy.hpp>
+#include <boost/geometry/geometries/polygon.hpp>
+#include <iostream>
+
+using namespace boost::geometry;
+using namespace std;
+
+int main()
+{
+	typedef model::d2::point_xy<double> pointtype;
+	pointtype point1(3, 3);
+	pointtype point2(2, 12.1);
+
+	model::polygon<pointtype> poly;
+	pointtype points[] = {pointtype(0, 0), pointtype(0, 10), pointtype(5, 15),
+						  pointtype(10, 10), pointtype(10, 0), pointtype(0, 0)};
+	append(poly, points);
+
+	cout << wkt(point1) << " is "
+		 << (within(point1, poly) ? "inside" : "outside of") << " the "
+		 << wkt(poly) << endl;
+	cout << wkt(point2) << " is "
+		 << (within(point2, poly) ? "inside" : "outside of") << " the "
+		 << wkt(poly) << endl;
+	return 0;
+}

+ 35 - 0
examples/30_gauss.cpp

@@ -0,0 +1,35 @@
+#include <boost/random.hpp>
+#include <cmath>
+#include <iostream>
+
+#define mean 0.0
+#define sigma 1.0
+#define EPS 0.01
+#define SAMPLES 10000000
+
+using namespace boost::random;
+using namespace std;
+
+int main()
+{
+	mt19937 rng(static_cast<unsigned int>(time(0)));
+	normal_distribution<double> dist(mean, sigma);
+
+	cout << "Generating numbers..." << endl;
+	int meanpoints = 0;
+	int epoints = 0;
+	for (int i = 0; i < SAMPLES; i++)
+	{
+		double rnd = dist(rng);
+		if (fabs(rnd - mean) < EPS)
+			meanpoints++;
+		if ((fabs(rnd - mean - sqrt(2) * sigma) < EPS) ||
+			(fabs(rnd - mean + sqrt(2) * sigma) < EPS))
+			epoints++;
+	}
+
+	cout << "Expected f(mean)/f(mean+sqrt(2)*sigma): " << M_E << endl;
+	cout << "Computed: " << meanpoints * 2.0 / epoints << endl;
+
+	return 0;
+}

+ 14 - 0
examples/31_regex.cpp

@@ -0,0 +1,14 @@
+#include <boost/regex.hpp>
+#include <iostream>
+#include <string>
+
+using namespace std;
+
+int main()
+{
+	string s = "Hello, world!";
+	boost::regex expr("(\\w+),\\s(\\w+)!");
+	string fmt("\\1, Boost.Regex!");
+	cout << boost::regex_replace(s, expr, fmt) << endl;
+	return 0;
+}

+ 25 - 0
examples/32_thread.cpp

@@ -0,0 +1,25 @@
+#include <boost/thread/thread.hpp>
+#include <cstdlib>
+#include <ctime>
+#include <iostream>
+#include <unistd.h>
+
+using namespace std;
+
+void threadfunc(int x)
+{
+	usleep(rand() % 100000);
+	cout << "Hello, Boost.Thread (id: " << x << ")" << endl;
+}
+
+int main()
+{
+	srand(time(0));
+
+	boost::thread t1(&threadfunc, 1);
+	boost::thread t2(&threadfunc, 2);
+
+	t1.join();
+	t2.join();
+	return 0;
+}

+ 29 - 0
examples/33_listdir.cpp

@@ -0,0 +1,29 @@
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
+#include <iostream>
+
+using namespace boost::filesystem;
+using namespace std;
+
+int main()
+{
+	path p("/sdcard");
+
+	if (!exists(p))
+	{
+		cout << p << " not found" << endl;
+		return 1;
+	}
+
+	if (!is_directory(p))
+	{
+		cout << p << " is not a directory" << endl;
+		return 1;
+	}
+
+	for (auto &d : directory_iterator(p))
+	{
+		cout << d << endl;
+	}
+	return 0;
+}

+ 15 - 0
examples/34_add.c

@@ -0,0 +1,15 @@
+#include <gmp.h>
+#include <stdio.h>
+
+int main()
+{
+	mpz_t a;
+	mpz_t b;
+	mpz_t c;
+	mpz_init_set_str(a, "123456789012345678901234567890", 10);
+	mpz_init_set_str(b, "555555555555555555555555555555", 10);
+	mpz_init(c);
+	mpz_add(c, a, b);
+	printf("%s + %s = %s\n", mpz_get_str(NULL, 10, a), mpz_get_str(NULL, 10, b), mpz_get_str(NULL, 10, c));
+	return 0;
+}

+ 13 - 0
examples/35_longfactorial.c

@@ -0,0 +1,13 @@
+#include <gmp.h>
+#include <stdio.h>
+
+int main()
+{
+	int n = 100;
+	mpz_t factorial;
+	mpz_init_set_ui(factorial, 1);
+	for (int i = 1; i <= n; i++)
+		mpz_mul_ui(factorial, factorial, i);
+	printf("Factorial of %d is %s\n", n, mpz_get_str(NULL, 10, factorial));
+	return 0;
+}

+ 15 - 0
examples/36_cppbindings.cpp

@@ -0,0 +1,15 @@
+#include <gmpxx.h>
+#include <iostream>
+
+using namespace std;
+
+int main()
+{
+	mpz_class a;
+	mpz_class b;
+	a = "123";
+	b = "321";
+	cout << a << " + " << b << " = " << a + b << endl;
+	cout << a << " * " << b << " = " << a * b << endl;
+	return 0;
+}

+ 28 - 0
examples/37_compute_e.c

@@ -0,0 +1,28 @@
+#include <stdio.h>
+#include <mpfr.h>
+
+#define ITER 100
+
+int main()
+{
+	mpfr_t e_tmp;
+	mpfr_t fact;
+	mpfr_t tmp;
+
+	mpfr_set_default_prec(256);
+	mpfr_init_set_ui(e_tmp, 1, MPFR_RNDD);
+	mpfr_init_set_ui(fact, 1, MPFR_RNDD);
+	mpfr_init(tmp);
+
+	for (int i = 1; i <= ITER; i++)
+	{
+		mpfr_mul_ui(fact, fact, i, MPFR_RNDD);
+		mpfr_set_d(tmp, 1.0, MPFR_RNDD);
+		mpfr_div(tmp, tmp, fact, MPFR_RNDD);
+		mpfr_add(e_tmp, e_tmp, tmp, MPFR_RNDD);
+	}
+	printf("Computed value of e is ");
+	mpfr_out_str(stdout, 10, 0, e_tmp, MPFR_RNDD);
+	printf("\n");
+	return 0;
+}

+ 27 - 0
examples/38_euler_formula.c

@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <mpc.h>
+#include <mpfr.h>
+
+#define PREC 256
+
+int main()
+{
+	mpc_t rx;
+	mpc_t ipi4;
+	mpfr_t pi;
+
+	mpfr_set_default_prec(PREC);
+	mpc_init2(rx, PREC);
+	mpc_init2(ipi4, PREC);
+	mpfr_init(pi);
+	mpfr_const_pi(pi, MPFR_RNDD);
+	mpc_set_fr(ipi4, pi, MPC_RNDDD);
+	mpc_mul_i(ipi4, ipi4, 1, MPC_RNDDD);
+	mpc_div_ui(ipi4, ipi4, 4, MPC_RNDDD);
+	mpc_exp(rx, ipi4, MPC_RNDDD);
+
+	printf("Computed value of e^(i*pi/4) is ");
+	mpc_out_str(stdout, 10, 0, rx, MPC_RNDDD);
+	printf("\n");
+	return 0;
+}

+ 15 - 0
examples/39_hellosqlite.c

@@ -0,0 +1,15 @@
+#include <sqlite3.h>
+#include <stdio.h>
+
+int main(void)
+{
+	sqlite3 *db;
+	sqlite3_stmt *res;
+	sqlite3_open(":memory:", &db);
+	sqlite3_prepare_v2(db, "SELECT \"Hello, SQLite3!\"", -1, &res, NULL);
+	sqlite3_step(res);
+	printf("%s\n", sqlite3_column_text(res, 0));
+	sqlite3_finalize(res);
+	sqlite3_close(db);
+	return 0;
+}

+ 27 - 0
examples/40_insandsel.c

@@ -0,0 +1,27 @@
+#include <sqlite3.h>
+#include <stdio.h>
+
+int main()
+{
+	sqlite3 *db;
+	sqlite3_stmt *res;
+	sqlite3_open(":memory:", &db);
+	sqlite3_exec(db, "CREATE TABLE strings(s TEXT)", 0, 0, 0);
+	for (int i = 0; i < 10; i++)
+	{
+		char tmp[1024];
+		sprintf(tmp, "INSERT INTO strings VALUES ('string%d')", i);
+		sqlite3_exec(db, tmp, 0, 0, 0);
+	}
+	sqlite3_prepare_v2(db, "SELECT * FROM strings", -1, &res, NULL);
+	printf("Database contents:\n");
+	int rc = sqlite3_step(res);
+	while (rc != SQLITE_DONE)
+	{
+		printf("%s\n", sqlite3_column_text(res, 0));
+		rc = sqlite3_step(res);
+	}
+	sqlite3_finalize(res);
+	sqlite3_close(db);
+	return 0;
+}

+ 74 - 0
examples/41_kvdb.c

@@ -0,0 +1,74 @@
+#include <sqlite3.h>
+#include <stdio.h>
+#include <string.h>
+
+int main()
+{
+	sqlite3 *db;
+	sqlite3_open(":memory:", &db);
+	sqlite3_exec(db, "CREATE TABLE kvdb(id TEXT PRIMARY KEY,val TEXT)", 0, 0, 0);
+	printf("Welcome to the simplest key-value database\n");
+	while (1)
+	{
+		char tmp[1024];
+		printf("What do you want to do?\n");
+		printf("Enter P to [P]ut, G to [G]et or L to [L]ist\n");
+		printf("Or enter Q to [Q]uit\n");
+		gets(tmp);
+		if (!strcmp(tmp, "P"))
+		{
+			char key[1024];
+			char data[1024];
+			printf("Enter key: ");
+			gets(key);
+			printf("Enter data: ");
+			gets(data);
+			sqlite3_stmt *ins;
+			sqlite3_prepare_v2(db, "INSERT OR REPLACE INTO kvdb VALUES (?,?)", -1, &ins, NULL);
+			sqlite3_bind_text(ins, 1, key, -1, SQLITE_STATIC);
+			sqlite3_bind_text(ins, 2, data, -1, SQLITE_STATIC);
+			sqlite3_step(ins);
+			sqlite3_finalize(ins);
+			continue;
+		}
+		if (!strcmp(tmp, "G"))
+		{
+			char key[1024];
+			printf("Enter key: ");
+			gets(key);
+			sqlite3_stmt *res;
+			sqlite3_prepare_v2(db, "SELECT val FROM kvdb WHERE id=?", -1, &res, NULL);
+			sqlite3_bind_text(res, 1, key, -1, SQLITE_STATIC);
+			int rc = sqlite3_step(res);
+			if (rc != SQLITE_DONE)
+			{
+				printf("Your data: %s\n", sqlite3_column_text(res, 0));
+			}
+			else
+				printf("No such key\n");
+			sqlite3_finalize(res);
+			continue;
+		}
+		if (!strcmp(tmp, "L"))
+		{
+			sqlite3_stmt *res;
+			sqlite3_prepare_v2(db, "SELECT * FROM kvdb", -1, &res, NULL);
+			printf("DB contents:\n");
+			int rc = sqlite3_step(res);
+			while (rc != SQLITE_DONE)
+			{
+				printf("%s: %s\n", sqlite3_column_text(res, 0), sqlite3_column_text(res, 1));
+				rc = sqlite3_step(res);
+			}
+			sqlite3_finalize(res);
+			continue;
+		}
+		if (!strcmp(tmp, "Q"))
+		{
+			printf("Bye\n");
+			break;
+		}
+	}
+	sqlite3_close(db);
+	return 0;
+}

+ 15 - 0
examples/42_helloncurses.c

@@ -0,0 +1,15 @@
+#include <ncurses.h>
+
+int main()
+{
+	initscr();
+	printw("Hello, ncurses!\n");
+	refresh();
+	int ch;
+	while ((ch = getch()) == KEY_RESIZE)
+	{
+		// KEY_RESIZE event usually appears when keyboard shows in Terminal on Android
+	}
+	endwin();
+	return 0;
+}

+ 23 - 0
examples/43_colors.c

@@ -0,0 +1,23 @@
+#include <ncurses.h>
+
+int main()
+{
+	initscr();
+	start_color();
+	init_pair(1, COLOR_YELLOW, COLOR_BLACK);
+	init_pair(2, COLOR_BLACK, COLOR_GREEN);
+	attron(COLOR_PAIR(1));
+	printw("Yellow text on black background\n");
+	attroff(COLOR_PAIR(1));
+	attron(COLOR_PAIR(2));
+	printw("Black text on green background\n");
+	attroff(COLOR_PAIR(2));
+	refresh();
+	int ch;
+	while ((ch = getch()) == KEY_RESIZE)
+	{
+		// KEY_RESIZE event usually appears when keyboard shows in Terminal on Android
+	}
+	endwin();
+	return 0;
+}

+ 36 - 0
examples/44_cursorctl.c

@@ -0,0 +1,36 @@
+#include <ncurses.h>
+#include <sys/param.h>
+
+int main()
+{
+	initscr();
+	printw("Press WASD to move the cross, Q to quit\n");
+	int x = 10;
+	int y = 10;
+	refresh();
+	int ch = 0;
+	noecho();
+	while (ch != 'q')
+	{
+		ch = getch();
+		int sy, sx;
+		getmaxyx(stdscr, sy, sx);
+		move(y, x);
+		delch();
+		if (ch == 'w')
+			y--;
+		if (ch == 's')
+			y++;
+		if (ch == 'a')
+			x--;
+		if (ch == 'd')
+			x++;
+		y = MAX(1, MIN(sy - 1, y));
+		x = MAX(0, MIN(sx - 1, x));
+		move(y, x);
+		addch('X');
+		refresh();
+	}
+	endwin();
+	return 0;
+}

+ 61 - 0
examples/45_fire.c

@@ -0,0 +1,61 @@
+// Originally written by Matthew Simpson in Python: https://gist.github.com/msimpson/1096950
+#include <ncurses.h>
+#include <stdlib.h>
+#include <string.h>
+
+static int *b = NULL;
+static int width;
+static int height;
+static int size;
+
+static void sizechanged()
+{
+	getmaxyx(stdscr, height, width);
+	size = width * height;
+	b = (int *)realloc(b, (size + width + 1) * sizeof(int));
+	memset(b, 0, (size + width + 1) * sizeof(int));
+	clear();
+}
+
+int main()
+{
+	initscr();
+
+	const char *charz[] = {" ", ".", ":", "^", "*", "x", "s", "S", "#", "$"};
+
+	curs_set(0);
+	start_color();
+	init_pair(1, COLOR_BLACK, COLOR_BLACK);
+	init_pair(2, COLOR_RED, COLOR_BLACK);
+	init_pair(3, COLOR_YELLOW, COLOR_BLACK);
+	init_pair(4, COLOR_BLUE, COLOR_BLACK);
+
+	sizechanged();
+
+	while (1)
+	{
+		for (int i = 0; i < width / 9; i++)
+			b[(rand() % width) + width * (height - 1)] = 65;
+		for (int i = 0; i < size; i++)
+		{
+			b[i] = (b[i] + b[i + 1] + b[i + width] + b[i + width + 1]) / 4;
+			int color = ((b[i] > 15) ? 4 : ((b[i] > 9) ? 3 : ((b[i] > 4) ? 2 : 1)));
+			if (i < size - 1)
+			{
+				attrset(COLOR_PAIR(color) | A_BOLD);
+				move(i / width, i % width);
+				addstr(charz[((b[i] > 9) ? 9 : b[i])]);
+			}
+		}
+
+		refresh();
+		timeout(30);
+		int ch = getch();
+		if ((ch != -1) && (ch != KEY_RESIZE))
+			break;
+		if (ch == KEY_RESIZE)
+			sizechanged();
+	}
+	endwin();
+	return 0;
+}

+ 22 - 0
examples/46_getexample.c

@@ -0,0 +1,22 @@
+#include <curl/curl.h>
+#include <stdio.h>
+#include <unistd.h>
+
+size_t writefunc(void *ptr, size_t size, size_t nmemb, void *unused)
+{
+	write(STDOUT_FILENO, ptr, size * nmemb);
+	return size * nmemb;
+}
+
+#define URL "http://example.com"
+
+int main()
+{
+	printf("Loading " URL "\n");
+	CURL *curl = curl_easy_init();
+	curl_easy_setopt(curl, CURLOPT_URL, URL);
+	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
+	curl_easy_perform(curl);
+	curl_easy_cleanup(curl);
+	return 0;
+}

+ 25 - 0
examples/47_postexample.c

@@ -0,0 +1,25 @@
+#include <curl/curl.h>
+#include <stdio.h>
+#include <unistd.h>
+
+size_t writefunc(void *ptr, size_t size, size_t nmemb, void *unused)
+{
+	write(STDOUT_FILENO, ptr, size * nmemb);
+	return size * nmemb;
+}
+
+#define URL "http://example.com"
+#define DATA "data=hellofromcurl"
+
+int main()
+{
+	printf("Posting " DATA " to " URL "\n");
+	CURL *curl = curl_easy_init();
+	curl_easy_setopt(curl, CURLOPT_URL, URL);
+	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
+	// That's all you need to do POST queries, the output will be ignored by example.com though
+	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, DATA);
+	curl_easy_perform(curl);
+	curl_easy_cleanup(curl);
+	return 0;
+}

+ 36 - 0
examples/48_sslexample.c

@@ -0,0 +1,36 @@
+#include <curl/curl.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#define URL "https://example.com"
+
+size_t nop(void *ptr, size_t size, size_t nmemb, void *unused)
+{
+	return size * nmemb;
+}
+
+int main()
+{
+	printf("Loading " URL "\n");
+	CURL *curl = curl_easy_init();
+	curl_easy_setopt(curl, CURLOPT_URL, URL);
+	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, nop);
+	curl_easy_setopt(curl, CURLOPT_CERTINFO, 1);
+	curl_easy_perform(curl);
+	struct curl_certinfo *certinfo;
+	curl_easy_getinfo(curl, CURLINFO_CERTINFO, &certinfo);
+	if (certinfo)
+	{
+		for (int i = 0; i < certinfo->num_of_certs; i++)
+		{
+			struct curl_slist *slist;
+			for (slist = certinfo->certinfo[i]; slist; slist = slist->next)
+				printf("%s\n", slist->data);
+		}
+	}
+	else
+		printf("Error loading SSL information\n");
+
+	curl_easy_cleanup(curl);
+	return 0;
+}

+ 71 - 0
settings.json

@@ -0,0 +1,71 @@
+{
+    "workbench.activityBar.visible": false,
+    "editor.fontFamily": "'Fixedsys Excelsior 3.01',Consolas, 'Courier New', monospace",
+    "editor.fontSize": 16,
+    "terminal.integrated.fontFamily": "宋体",
+    "security.workspace.trust.untrustedFiles": "open",
+    "code-runner.clearPreviousOutput": true,
+    "editor.lineHeight": 1.1,
+    "git.ignoreMissingGitWarning": true,
+    "extensions.ignoreRecommendations": true,
+    "vscodeGoogleTranslate.preferredLanguage": "Chinese (Simplified)",
+    "C_Cpp.clang_format_fallbackStyle": "LLVM",
+    "code-runner.executorMap": {
+        "javascript": "node",
+        "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
+        "zig": "zig run",
+        "objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
+        "php": "php",
+        "python": "python -u",
+        "perl": "perl",
+        "perl6": "perl6",
+        "ruby": "ruby",
+        "go": "go run",
+        "lua": "lua",
+        "groovy": "groovy",
+        "powershell": "powershell -ExecutionPolicy ByPass -File",
+        "bat": "cmd /c",
+        "shellscript": "bash",
+        "fsharp": "fsi",
+        "csharp": "scriptcs",
+        "vbscript": "cscript //Nologo",
+        "typescript": "ts-node",
+        "coffeescript": "coffee",
+        "scala": "scala",
+        "swift": "swift",
+        "julia": "julia",
+        "crystal": "crystal",
+        "ocaml": "ocaml",
+        "r": "Rscript",
+        "applescript": "osascript",
+        "clojure": "lein exec",
+        "haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
+        "rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
+        "racket": "racket",
+        "scheme": "csi -script",
+        "ahk": "autohotkey",
+        "autoit": "autoit3",
+        "dart": "dart",
+        "pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
+        "d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
+        "haskell": "runghc",
+        "nim": "nim compile --verbosity:0 --hints:off --run",
+        "lisp": "sbcl --script",
+        "kit": "kitc --run",
+        "v": "v run",
+        "sass": "sass --style expanded",
+        "scss": "scss --style expanded",
+        "less": "cd $dir && lessc $fileName $fileNameWithoutExt.css",
+        "FortranFreeForm": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
+        "fortran-modern": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
+        "fortran_fixed-form": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
+        "fortran": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
+        "sml": "cd $dir && sml $fileName",
+        //  VS Code 配置 CodeRunner 使用 MSVC编译器
+        // "cpp": "cd $dir && astyle --ascii $fileName && cl.exe /nologo /w /EHsc /Ox /DNDEBUG /MD $fileName  /link rpcrt4.lib msvcrt.lib shell32.lib && $dir$fileNameWithoutExt",
+        // "c": "cd $dir  && astyle --ascii $fileName && cl.exe /nologo /w /EHsc /Ox /DNDEBUG /MD $fileName  /link rpcrt4.lib msvcrt.lib && $dir$fileNameWithoutExt"
+        "cpp": "cd $dir &&  cl.exe /nologo /w /EHsc /Ox /DNDEBUG /MD $fileName  /link rpcrt4.lib msvcrt.lib shell32.lib && $dir$fileNameWithoutExt",
+        "c": "cd $dir  &&  cl.exe /nologo /w /EHsc /Ox /DNDEBUG /MD $fileName  /link rpcrt4.lib msvcrt.lib && $dir$fileNameWithoutExt"
+
+    }
+}