当前位置: 首页>>代码示例>>C++>>正文


C++ Students::push_back方法代码示例

本文整理汇总了C++中Students::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ Students::push_back方法的具体用法?C++ Students::push_back怎么用?C++ Students::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Students的用法示例。


在下文中一共展示了Students::push_back方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char* argv[]) {
    ifstream file;
    string data;
    vector<string> tokens;
    Courses courses;
    Students students;

    file.open("courses.conf");
    if (!file.is_open()) {
        cout << "Failed opening courses.conf." << endl;
        return 0;
    }
    while (getline(file, data)) {
        tokens = str_split(data, ',');
        // data: WEEKDAY,COURSE-ID,SPACE
        Course* course = new Course(*(tokens[0].c_str()) - '0', 
                                    tokens[1], 
                                    atoi(tokens[2].c_str()));
        courses.push_back(course);
    }
    file.close();

    file.open("students.conf");
    if (!file.is_open()) {
        cout << "Failed opening students.conf." << endl;
        return 0;
    }

    while (getline(file, data)) {
        tokens = str_split(data, ',');

        // data: STUD-ID,COURSE-ID1,COURSE-ID2,...,COURSE-IDN
        Student* student = new Student(tokens[0]);
        if (tokens.size() > 1) {
            for (size_t i = 1; i < tokens.size(); ++i) {
                for (size_t j = 0; j < courses.size(); ++j) {
                    if (courses[j]->getCourseId() == tokens[i]) {
                        if (courses[j]->addStudent(student)) {
                            // we have found a room for this student
                            // in the course he requested, so we are breaking
                            // the search for room.
                            // NOTE: we are not break;'ing when we find 
                            // a matching course because there might be 
                            // room in another day for this course.
                            break;
                        }
                    }
                }
            }
        }

        students.push_back(student);
    }
    
    file.close();

    // clean output files
    ofstream output;
    output.open("courses.out");
    output.close();
    output.open("students.out");
    output.close();

    for (size_t i = 0; i < courses.size(); ++i) {
        courses[i]->print("courses.out");
    }

    for (size_t i = 0; i < students.size(); ++i) {
        students[i]->print("students.out");
    }

    for (size_t i = 0; i < courses.size(); ++i) {
        delete courses[i];
        courses[i] = 0;
    }

    for (size_t i = 0; i < students.size(); ++i) {
        delete students[i];
        students[i] = 0;
    }

    return 0;
}
开发者ID:dvirazulay,项目名称:homework,代码行数:83,代码来源:matrixU.cpp


注:本文中的Students::push_back方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。