我試圖遍歷並輸出向量,但除了要求我輸入外沒有任何事情發生。C++沒有cout信息顯示
int main() {
string a;
vector<string> test;
while (std::cin>>a) {
test.push_back(a);
}
for (vector<string>::iterator i= test.begin(); i!= test.end(); ++i) {
std::cout << *i << std::endl;
}
system("pause");
return 0;
}
所以你的問題不是擺脫while循環,與cout無關? – TZHX
你如何期望從這個循環中逃脫:'while(std :: cin >> a)'? –
我打算在輸入完成時跳出循環。 –