c++ 输出vector 字符串
时间: 2023-10-19 09:34:51 浏览: 129
C++ vector
要输出vector字符串,你可以使用for循环遍历vector并打印每个元素。下面是一个示例代码:
```
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
vector<string> words = {"c", "is", "a", "good", "word"};
for (string word : words) {
cout << word << endl;
}
return 0;
}
```
在这个例子中,我们定义了一个vector<string>类型的变量words,并初始化它包含了一些字符串元素。然后,我们使用for循环遍历words中的每个元素,并打印输出到屏幕上。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [C++快速讲解(二):字符串和vector](https://blog.csdn.net/qq_32306361/article/details/114849973)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文