我想繼續閱讀Stroustrup PPUC++,但我卡住了!幾天前我寫了一個BleepOutTheBadWords程序,它工作。我試圖在幾天前和我的弟弟寫程序,但我失敗了。這本質上是我寫的一個程序,用來確定哪裏出了問題。它不打印出「句子」向量中的每個單詞。C++ Xcode不會運行我的for循環(很短)
#include <iostream>
#include "std_lib_facilities.h" // Stroustrup header file
using namespace std;
int main()
{
cout << "Write a sentence." << endl;
vector<string> sentence;
// Put user input into "sentence" vector
for (string word; cin >> word;)
sentence.push_back(word);
// Print each word in "sentence" vector
for (int i = 0; i < sentence.size(); ++i)
cout << sentence[i] << endl;
// Keep window open and return 0 to show program succeeded
keep_window_open();
return 0;
}
答案很明顯。如果你真的很好,請說明一下。在發佈之前,我瀏覽了兩個不同頁面上的建議讀物。
什麼是「我失敗了」?問一個具體的問題。 –
如果很明顯,你不需要問這個問題。你的問題應該包含所需的行爲和實際行爲。 「失敗」的含義是什麼? – user463035818