c++如何读取字符串中的某个字符

  • c++如何读取字符串中的某个字符

    可以使用下标或者迭代器来访问字符串中的某个字符。下面是两种方法:使用下标:#include #include int main() {std::string str = “Hello, world!”;char ch = str[4]; // 通过下标访问字符串中的第5个字符,索引从0开始std::cout << "The fifth character is

    2024-04-12
    0