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
| #include <iostream> #include <string> #include <format> using namespace std;
static inline void ltrim(std::string& s) { auto endPosition = std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); }); s.erase(s.begin(), endPosition); }
static inline void rtrim(std::string& s) { auto startPosition = std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(); s.erase(startPosition, s.end()); }
static inline void trim(std::string& s) { rtrim(s); ltrim(s); }
int main() { auto str1{ " liulun "s }; trim(str1); cout << str1 << endl;
int num1 = stoi("1237"s); double num2 = stod("123.45"s); cout << num1 << " " << num2 << endl;
auto str2 = to_string(num1); auto str3 = to_string(num2); cout << str2 << " " << str3 << endl;
auto str4{ "他1926年8月17日出生,2022年11月30日逝世,是江苏省扬州市人。"s }; cout << str4.substr(21, 19) << endl; cout << str4.find("2022") << endl; cout << format("他{0}年8月17日出生,{1}年11月30日逝世,他{0}年8月17日出生,{1}年11月30日逝世。", "1926", "2022"); auto c = getchar(); }
|