我为我的一个项目创建了一个调度算法,但首先是从文本文件中提取所有相关信息。我在文本文件中有课程名称,编号和说明。我创建了一个正则表达式来从文件中获取描述,但我不知道如何打印出我得到的内容。任何帮助,将不胜感激。
#pragma once
using namespace std;
class Course
{
private:
string subject;
string fourDigitNumber;
string description;
string teacherName;
string timeSlot;
public:
Course();
Course(string subjectArg, string fourDigitNumberArg, string descriptionArg, string teacherNameArg, string timeSlotArg);
void readCourses(string strFile, vector<Course> courses, ifstream &fileOpen);
void printinfo();
};
Course::Course(string subjectArg, string fourDigitNumberArg, string descriptionArg, string teacherNameArg, string timeSlotArg) {
subject = subjectArg;
fourDigitNumber = fourDigitNumberArg;
description = descriptionArg;
teacherName = teacherNameArg;
timeSlot = timeSlotArg;
}
void Course::readCourses(string strFile, vector<Course> courses, ifstream &fileOpen) {
string subject;
string fourDigitNumber;
string description;
string teacherName;
string timeSlot;
string line;
regex firstReg("Descriptionstart\n((.+\n)+)Descriptionend");
fileOpen.open("Coursedatabase.txt");
cout << "testing" << endl;
if (fileOpen.is_open())
{
while (fileOpen.good()) {
getline(fileOpen, line);
smatch result;
regex_search(line, result, firstReg);
if (result[1].str().length() > 0)
{
cout << result[1].str() << endl;
printinfo();
}
}
double value;
/*
while (fileOpen >> value) {
fileOpen.putback(value);
}
*/
}
}
void Course::printinfo() {
cout <<
}
Course::Course() {
}
测试驱动程序:
#include <iostream>
#include <string>
#include <fstream>
#include <istream>
#include <regex>
#include <vector>
#include <regex>
#include "Course.h"
using namespace std;
int main() {
vector<Course> courses;
Course course1;
course1.printinfo();
cin.get();
}
另一方面,我的逻辑是正确的吗?完成描述后,我必须为课程名称和老师做。然后,当我完成这项工作时,我将创建一个时隙数组,然后只需在fcfs基础上插入时间段,然后显示所有课程信息。