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();
}
相关推荐
吐泡泡_1 天前
C++20(概念和约束)
c++20
訫悦4 天前
体验在Qt中简单使用C++20的协程
qt·c++20·协程
fpcc8 天前
C++20中的预处理器宏——__VA_OPT__
c++20
Codeking__10 天前
C++20的consteval和constinit(接C++11的constexpr)
算法·c++20
六bring个六13 天前
C++20协程
c++20·协程
C++实习生13 天前
Visual C++ 2005 Express 中文版
express·c++20
Ethan Wilson15 天前
VS2019 C++20 模块相关 C1001: 内部编译器错误
开发语言·c++·c++20
DYS_房东的猫15 天前
《 C++ 零基础入门教程》第10章:C++20 核心特性 —— 编写更现代、更优雅的 C++
java·c++·c++20
ice_junjun25 天前
C++20 线程返回值处理指南
c++20·c++ 多线程返回值
凌乱风雨12111 个月前
从源码角度解析C++20新特性如何简化线程超时取消
前端·算法·c++20