forked from parallel101/course
-
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
Showing
7 changed files
with
69 additions
and
18 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,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; | ||
} |
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 |
---|---|---|
@@ -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; | ||
} |
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 |
---|---|---|
@@ -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; | ||
} |
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,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; | ||
} |
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,9 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
cout << string("hello\0cpp") << endl; | ||
cout << string("hello\0cpp", 9) << endl; | ||
} |
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,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 not shown.