<分区>
我想继续阅读 Stroustrup PPUC++,但我被卡住了!几天前我写了一个 BleepOutTheBadWords 程序,它工作了。前几天试着和弟弟一起写程序,失败了。这本质上是我编写的一个程序,用于找出问题所在。它不会打印出“句子” vector 中的每个单词。
#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;
}
答案很明显。如果您很友善,请只说出显而易见的事情。在发布这篇文章之前,我浏览了两个不同页面上的建议阅读 Material 。