std::string从C++20支持的新Operations

https://en.cppreference.com/w/cpp/string/basic_string

cpp 复制代码
#include <iostream>
#include <string>
#include <format>

void test_01()
{
    int val = std::stoi("101");
    std::cout << std::format("{}\n", val);  // 101

    std::string str("Hello C++20!");
    if(str.ends_with("C++20!")){
        std::cout << std::format("{} ends with \"{}\"\n",str, "C++20!");  // Hello C++20! ends with "C++20!"
    }
    if(str.starts_with("Hello")){
        std::cout << std::format("{} starts with \"{}\"\n",str, "Hello");  // Hello C++20! ends with "C++20!"
    }
    if(str.contains("C++23")){
        std::cout << std::format("{} contains \"{}\"\n",str, "C++23");
    }
    else {
        // std::basic_string<CharT,Traits,Allocator>::contains is supported from "C++23".
        std::cout << std::format("std::basic_string<CharT,Traits,Allocator>::contains is supported from \"{}\".\n", "C++23");
    }
}
 
int main()
{
    test_01();
}
相关推荐
hggngx548h8 天前
有哪些C++20特性可以在Dev-C++中使用?
开发语言·c++·c++20
R&L_2018100110 天前
C++20之三路比较运算符
c++20·c++ 新特性
buvsvdp50059ac11 天前
如何在Visual Studio中启用C++17或C++20?
c++·c++20·visual studio
TiAmo zhang13 天前
现代C++的AI革命:C++20/C++23核心特性解析与实战应用
c++·人工智能·c++20
m0_7482480213 天前
C++20 协程:在 AI 推理引擎中的深度应用
java·c++·人工智能·c++20
落羽的落羽14 天前
【C++】现代C++的新特性constexpr,及其在C++14、C++17、C++20中的进化
linux·c++·人工智能·学习·机器学习·c++20·c++40周年
kyle~18 天前
CPU调度---协程
java·linux·服务器·数据库·c++20
charlie1145141911 个月前
精读C++20设计模式:行为型设计模式:中介者模式
c++·学习·设计模式·c++20·中介者模式
charlie1145141911 个月前
理解C++20的革命特性——协程引用之——利用协程做一个迷你的Echo Server
网络·学习·socket·c++20·协程·epoll·raii
charlie1145141912 个月前
理解C++20的革命特性——协程支持2:编写简单的协程调度器
c++·学习·算法·设计模式·c++20·协程·调度器