/*vector_example.cpp*/
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
vector<string> msg = {"Hello", "C++", "World", "from", "VSCode", "and the C++ extension!"};
for (const string& word : msg) {
cout << word << " ";
}
cout << endl;
return 0;
}
vector.size()
返回向量中元素个数- C++中的
std::string
可以视为std::vector<char>
类型的向量,因此可以用.size()
函数返回字符串的字符长度(不含'\n'结尾符号)。 - C++打印vector数据: https://www.geeksforgeeks.org/how-to-iterate-through-a-vector-without-using-iterators-in-c/