-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadme.txt
More file actions
executable file
·184 lines (128 loc) · 4.76 KB
/
readme.txt
File metadata and controls
executable file
·184 lines (128 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
1. 编译如下:
g++ CHAPTER1-1.cpp -o CHAPTER1-1
g++ ./cpp_stl_guide_code/Chapter1/CHAPTER1-2.cpp -o ./build/CHAPTER1-2
./build/CHAPTER1-2 111 22344
g++ ./cpp_stl_guide_code/Chapter1/CHAPTER1-3.cpp -o ./build/CHAPTER1-3
./build/CHAPTER1-3
gcc ./cpp_stl_guide_code/Chapter2/CHAPTER2-1.c -o ./build/CHAPTER2-1
./build/CHAPTER2-1
gcc ./cpp_stl_guide_code/Chapter2/CHAPTER2-2.c -o ./build/CHAPTER2-2
./build/CHAPTER2-2
gcc ./cpp_stl_guide_code/Chapter2/CHAPTER2-4.c -o ./build/CHAPTER2-4
./build/CHAPTER2-4
gcc ./cpp_stl_guide_code/Chapter2/CHAPTER2-5.c -o ./build/CHAPTER2-5
./build/CHAPTER2-5
# Chapter5
gcc ./cpp_stl_guide_code/Chapter5/Chapter5-1.c -o ./build/Chapter5-1
gcc ./cpp_stl_guide_code/Chapter5/Chapter5-2.c -o ./build/Chapter5-2
gcc ./cpp_stl_guide_code/Chapter5/Chapter5-3.c -o ./build/Chapter5-3
gcc ./cpp_stl_guide_code/Chapter5/Chapter5-4.c -o ./build/Chapter5-4
gcc ./cpp_stl_guide_code/Chapter5/Chapter5-5.c -o ./build/Chapter5-5
#空指针应用
gcc ./cpp_stl_guide_code/Chapter5/Chapter5-6.c -o ./build/Chapter5-6
./build/Chapter5-6
str1=111saaac len=8
#空字符串
gcc ./cpp_stl_guide_code/Chapter5/Chapter5-7.c -o ./build/Chapter5-7
./cpp_stl_guide_code/Chapter5/Chapter5-7.c: In function ‘main’:
./cpp_stl_guide_code/Chapter5/Chapter5-7.c:6:39: warning: implicit declaration of function ‘strlen’ [-Wimplicit-function-declaration]
6 | printf("str=%s &len=%d ", str, (int)strlen(str));
| ^~~~~~
./cpp_stl_guide_code/Chapter5/Chapter5-7.c:2:1: note: include ‘<string.h>’ or provide a declaration of ‘strlen’
1 | #include <stdio.h>
+++ |+#include <string.h>
2 | //#include <string.h>
./cpp_stl_guide_code/Chapter5/Chapter5-7.c:6:39: warning: incompatible implicit declaration of built-in function ‘strlen’ [-Wbuiltin-declaration-mismatch]
6 | printf("str=%s &len=%d ", str, (int)strlen(str));
| ^~~~~~
./cpp_stl_guide_code/Chapter5/Chapter5-7.c:6:39: note: include ‘<string.h>’ or provide a declaration of ‘strlen’
缺失string.h头文件;
./build/Chapter5-7
str= &len=0
#字符串反转
1. 例1:
gcc ./cpp_stl_guide_code/Chapter5/Chapter5-8.c -o ./build/Chapter5-8
./build/Chapter5-8
buf no inverse:abcdefg
buf:gfedcba
sh: 1: pause: not found
例如2:
gcc ./cpp_stl_guide_code/Chapter5/Chapter5-9.c -o ./build/Chapter5-9
./build/Chapter5-9
src no inverse1:abcdefg
Reversed string:gfedcba
sh: 1: pause: not found
gcc ./cpp_stl_guide_code/Chapter5/Chapter5-10.c -o ./build/Chapter5-10
./build/Chapter5-10
Reversed string: olleh
例如3:改进:将逆序的结果存入一个全局变量,并进行打印
gcc ./cpp_stl_guide_code/Chapter5/Chapter5-8-1.c -o ./build/Chapter5-8-1
./build/Chapter5-8-1
buf no inverse:abcdefg
g_buf:gfedcba
sh: 1: pause: not found
改进:使用局部变量
gcc ./cpp_stl_guide_code/Chapter5/Chapter5-8-2.c -o ./build/Chapter5-8-2
./build/Chapter5-8-2
buf no inverse:abcdefg
g_buf:gfedcba
sh: 1: pause: not found
# Chapter6
g++ ./cpp_stl_guide_code/Chapter6/Chapter6-1.cpp -o ./build/Chapter6-1
#custom your exp
g++ ./cpp_stl_guide_code/Chapter6/Chapter6-3.cpp -o ./build/Chapter6-3
./build/Chapter6-3
My exception happened
g++ ./cpp_stl_guide_code/Chapter6/Chapter6-4.cpp -o ./build/Chapter6-4
./build/Chapter6-4
An exception occurred. Exception Nr. 20
g++ ./cpp_stl_guide_code/Chapter6/Chapter6-5.cpp -o ./build/Chapter6-5
./build/Chapter6-5
vector size = 0
extended vector size = 5
value of vec [0] = 0
value of vec [1] = 1
value of vec [2] = 2
value of vec [3] = 3
value of vec [4] = 4
value of v = 0
value of v = 1
value of v = 2
value of v = 3
value of v = 4
#函数模版()
g++ ./cpp_stl_guide_code/Chapter6/Chapter6-6.cpp -o ./build/Chapter6-6
./build/Chapter6-6
2
4
4
# 数组 指针 字符串应用
g++ ./cpp_stl_guide_code/Chapter6/Chapter6-7.cpp -o ./build/Chapter6-7
./cpp_stl_guide_code/Chapter6/Chapter6-7.cpp: In function ‘int main()’:
./cpp_stl_guide_code/Chapter6/Chapter6-7.cpp:9:16: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
9 | char *str1 = "abc";
| ^~~~~
./build/Chapter6-7
strcpy( str4, str1) : abc
strcpy( str4, str11) : dfj
strcpy( str4, str2) : 123
strcpy( str4, str4) : ccccc111
指针常量
int* const p1=new int(1);
常量指针
int const *p1=new int(1);
const int *p1=new int(1);
#指针操作
例1:
g++ ./cpp_stl_guide_code/Chapter6/Chapter6-8.cpp -o ./build/Chapter6-8
./build/Chapter6-8
var1 变量的地址: 0x7ffc29f1ab28
var2 变量的地址: 0x7ffc29f1ab2e
例2:
g++ ./cpp_stl_guide_code/Chapter6/Chapter6-9.cpp -o ./build/Chapter6-9
./build/Chapter6-9
Value of var variable:20
Address stored in ip variable:0x7ffddce80adc
Value of *ip variable:20
#C标准格式
int main( int argc, char *argv[] )