Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
archibate committed Jul 14, 2022
1 parent 60df4b5 commit 0eada5a
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 18 deletions.
12 changes: 12 additions & 0 deletions 15/04/f.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <string>
#include <iostream>
#include <functional>

using namespace std;

int main() {
string s = "+03.14e-03"s;
cout << "字符串: " << s << endl;
float f = stof(s);
cout << "浮点数: " << f << endl;
}
6 changes: 3 additions & 3 deletions 15/05/a.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <iostream>
#include <string>
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
cout << string("hello\0cpp") << endl;
cout << string("hello\0cpp", 9) << endl;
cout << "十六进制:" << hex << 42 << endl;
}
21 changes: 6 additions & 15 deletions 15/05/b.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
#include <string>
#include <string_view>
#include <iostream>
#include <sstream>
#include <iomanip>

using namespace std;

int main() {
string s1 = "hello";
string s2 = s1; // 深拷贝
string_view sv1 = s1; // 弱引用
string_view sv2 = sv1; // 浅拷贝
cout << "s1=" << s1 << endl;
cout << "s2=" << s2 << endl;
cout << "sv1=" << sv1 << endl;
cout << "sv2=" << sv2 << endl;
s1[0] = 'B';
cout << "修改s1后" << endl;
cout << "s1=" << s1 << endl;
cout << "s2=" << s2 << endl;
cout << "sv1=" << sv1 << endl;
cout << "sv2=" << sv2 << endl;
stringstream ss;
ss << "十六进制:" << hex << 42;
string s = ss.str();
cout << s << endl;
}
17 changes: 17 additions & 0 deletions 15/05/c.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <string>
#include <iostream>
#include <sstream>
#include <iomanip>

using namespace std;

int main() {
string s = "42yuan"s;
stringstream ss(s);
int num;
ss >> num;
string unit;
ss >> unit;
cout << "数字:" << num << endl;
cout << "单位:" << unit << endl;
}
9 changes: 9 additions & 0 deletions 15/07/a.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <iostream>
#include <string>

using namespace std;

int main() {
cout << string("hello\0cpp") << endl;
cout << string("hello\0cpp", 9) << endl;
}
22 changes: 22 additions & 0 deletions 15/07/b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <string>
#include <string_view>
#include <iostream>

using namespace std;

int main() {
string s1 = "hello";
string s2 = s1; // 深拷贝
string_view sv1 = s1; // 弱引用
string_view sv2 = sv1; // 浅拷贝
cout << "s1=" << s1 << endl;
cout << "s2=" << s2 << endl;
cout << "sv1=" << sv1 << endl;
cout << "sv2=" << sv2 << endl;
s1[0] = 'B';
cout << "修改s1后" << endl;
cout << "s1=" << s1 << endl;
cout << "s2=" << s2 << endl;
cout << "sv1=" << sv1 << endl;
cout << "sv2=" << sv2 << endl;
}
Binary file modified 15/slides.pptx
Binary file not shown.

0 comments on commit 0eada5a

Please sign in to comment.