测量string字符串长度
时间: 2023-09-27 20:12:03 浏览: 128
回答: 你可以使用string类的length()函数来测量string字符串的长度,而不必使用strlen函数。例如,你可以像这样编写代码来测量string字符串的长度:
#include <iostream>
#include <string>
using namespace std;
int main() {
string a;
cin >> a;
int count = a.length();
cout << count;
}
这段代码中,我们使用了string类的length()函数来获取string字符串的长度,并将结果存储在count变量中,然后将count打印出来。这样就可以得到string字符串的长度了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [String类型的测量长度](https://blog.csdn.net/qq_35424155/article/details/103333844)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [测量字符串长度(strlen,sizeof)](https://blog.csdn.net/zzsddre/article/details/125085288)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文