2
我想通過for循環將多個字符串添加到一個矢量中,我可以很容易地用一個數組來做到這一點,但我在向量上做同樣的事情時遇到了麻煩。下面是我想嘗試轉換爲矢量的數組的一個示例。通過循環的C++矢量輸入
陣列樣式
String StudentNames[];
int StudentNumbers;
for(int i = 0; StudentNumbers > i; i++){
cin >> StudentNames[i];
}
矢量樣式
vector<string> StudentNames;
int StudentNumbers;
//How do i add a for loop using vector and add strings to it similar to the array above?