要在C++中输出字符串的长度,可以使用std::string类的size()或length()方法来获取字符串的长度,然后将其输出。以下是一个简单的示例代码:
#include <iostream>
#include <string>
int main() {
std::string str = "Hello, World!";
std::cout << "Length of the string is: " << str.size() << std::endl;
return 0;
}
在上面的示例中,str.size()方法用于获取字符串str的长度,并将其输出到控制台。如果想要使用length()方法,也可以将str.length()替换为str.size()。
运行以上代码将输出:
Length of the string is: 13
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: 怎么用C++编写自己的逆向工程