要遍历std::vectorstd::string,可以使用for循环或者范围for循环。

使用for循环的示例代码如下:

std::vectorstd::string vec = {"hello", "world", "example"};

for (int i = 0; i < vec.size(); i++) { std::cout << vec[i] << std::endl; }

使用范围for循环的示例代码如下:

std::vectorstd::string vec = {"hello", "world", "example"};

for (const auto& str : vec) { std::cout << str << std::endl; }

stdvectorstdstring遍历

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

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