⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list_main.cpp

📁 Accelerated c++ 電子書 對 c++ container 多有描述
💻 CPP
字号:
#include <algorithm>
#include <list>
#include <string>

#include "grade.h"
#include "Student_info.h"

#ifdef _MSC_VER
#include "../minmax.h"
#else
using std::max;
#endif

using std::cin;
using std::cout;
using std::endl;
using std::list;
using std::string;

list<Student_info> extract_fails(list<Student_info>& v);

#ifdef _MSC_VER
// The definition of Student_info::operator< is necessary
// under Microsoft Visual C++ because the compiler does not
// support the ability to pass a comparison function as an
// argument to list::sort

bool operator<(const Student_info& x, const Student_info& y)
{
	return compare(x, y);
}
#endif

int main()
{
        list<Student_info> vs;
        Student_info s;
        string::size_type maxlen = 0;
        while (read(cin, s)) {
                maxlen = max(maxlen, s.name.size());
                vs.push_back(s);
        }

#ifdef _MSC_VER
	vs.sort();
#else
        vs.sort(compare);
#endif

	list<Student_info> fails = extract_fails(vs);

#ifdef _MSC_VER
	std::list<Student_info>::iterator i;
#else
	list<Student_info>::iterator i;
#endif

	for (i = fails.begin(); i != fails.end(); ++i)
		cout << i->name << " " << grade(*i) << endl;

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -