在C++中,你可以使用substr()函数来截取字符串的一部分。要去除字符串的后16个字符,你可以使用以下方法:

#include <iostream>
#include <string>

int main() {
    std::string str = "Hello World! This is a test string.";
    std::string newStr = str.substr(0, str.length() - 16);
    
    std::cout << newStr << std::endl;
    
    return 0;
}

在上面的代码中,我们使用substr()函数来截取从索引0开始,长度为原字符串长度减去16的子字符串。输出结果为:"Hello World! This is a test"。

linux c++ string去除字符串后16个字符

原文地址: https://www.cveoy.top/t/topic/ikl6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录