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();
}
相关推荐
啦啦啦啦啦zzzz10 天前
利用RAII机制进行日志的采集
linux·服务器·c++·网络编程·c++20
啦啦啦啦啦zzzz11 天前
Logger的组装(c++20)
c++·算法·c++20
啦啦啦啦啦zzzz14 天前
Appender抽象类的实现c++20
linux·服务器·c++·c++20
OPEN-F17 天前
C++20新特性精讲:概念、范围与三路比较
算法·c++20
小小龙学IT25 天前
C++ std::chrono 时间库深度解析:从 duration 模板到 C++20 日历与时区
linux·c++·c++20
郝学胜-神的一滴1 个月前
C++20 高级编程 004:从初始化、内存到const系列关键字
开发语言·算法·编程·软件构建·c++20
可爱系程序猿1 个月前
msvcp120.dll 加载失败排查:VC++ 2013、进程架构与插件私有目录如何对应
程序人生·电脑·c++20
ShineWinsu1 个月前
对于C++:C++20中线程、初始化、Lambda与内存视图等特性的解析
c++·c++20
可爱系程序猿1 个月前
mfc100.dll 加载失败排查:旧版 VC++ 2010 程序、位数与插件目录如何核对
程序人生·电脑·c++20
ShineWinsu1 个月前
对于 C++:C++20中Concept(概念) 与 Coroutine(协程)的解析
linux·开发语言·网络·c++·c++20·epoll