这是他们给了我一个任务:如何让我的程序打印“退出”之后由用户输入的所有数据都被输入
编写一个程序,反复要求用户输入一个句子并按下Enter键。您的程序会将用户输入的每个句子存储到某个容器中。当用户键入“退出”或“退出”时,按字母顺序将每个句子打印回屏幕,然后退出。
下面是我到目前为止有:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string data;
vector data;
do
{
cout << "Type a sentence and press enter."
"If the word 'exit' is typed, the program will close." << endl;
getline(cin, data);
// validate if data is not equals to "exit"
if (data != "exit" && data != "Exit")
{
// then type back
cout << data << endl;
}
}
while (data != "exit" && data != "Exit");
return 0;
}
有没有想过使用'qsort'函数?或者你可以使用@paddy建议的'std :: sort'。 –
我从来没有听说过。我的教授建议我们用矢量容器这样做。 –
'矢量数据;'?? - >'vector datav;','{while' - >'} while' –
BLUEPIXY