方法1:使用 scanf() != EOF 去检测是否读到了文件的末尾,见函数TestOne()
方法2:使用 while(cin >> str) 读取多个string值
待续…
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
// 方法1:使用 scanf() != EOF 去检测是否读到了文件的末尾,见函数TestOne()
void TestOne()
{
int count;
int tmp;
set<int> output;
while (scanf("%d", &count) != EOF)
{
for (int i = 0; i < count; ++i)
{
cin >> tmp;
output.insert(tmp);
}
for (auto iter = output.begin(); iter != output.end(); ++iter)
cout << *iter << endl;
output.clear();
}
}
// 方法2:使用 while(cin >> str) 读取多个string值
void TestTwo()
{
string str;
char ch;
stack<string> s;
while (cin >> str)
s.push(str);
while (s.size() > 0)
{
cout << s.top() << " ";
s.pop();
}
}
int main()
{
TestOne();
TestTwo();
system("pause");
return 0;
}
感谢阅读