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();
}
相关推荐
c++之路3 小时前
C++20概述
java·开发语言·c++20
故事还在继续吗1 天前
C++20关键特性
开发语言·c++·c++20
熊文豪2 天前
FinceptTerminal 深度解析:用 C++20 + Qt6 + Python 打造的开源 Bloomberg 终端
python·开源·c++20·bloomberg·finceptterminal
前进吧-程序员13 天前
现代 C++ 异步编程:从零实现一个高性能 ThreadPool (C++20 深度实践)
开发语言·c++·c++20
君鼎14 天前
C++20 新特性全面总结
算法·c++20
十五年专注C++开发23 天前
UDRefl: 一个基于C++20的高性能动态反射库
c++20·反射·udrefl
前进吧-程序员23 天前
C++20 Concepts 简明介绍:模板编程的“合约时代”
c++20
w我是东山啊1 个月前
C++20——协程
c++20
wangjialelele1 个月前
C++11、C++14、C++17、C++20新特性解析(一)
linux·c语言·开发语言·c++·c++20·visual studio
telllong1 个月前
C++20 Modules:从入门到真香
java·前端·c++20