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


C++ Student::end方法代码示例

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


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

示例1: exportStudent

void Gradebook::exportStudent(const string studentID,  string saveLocation) const
{
	vector<string> newFields;
	vector<string> newData;

	for(set<Course>::const_iterator course = m_courses.begin(); course != m_courses.end(); ++course)
	{
		string courseName = course->m_courseName;
		int year = course->m_year;
		string semester = SemesterString[course->m_semester];
		int idField = 0;
		int nameField = 0;

		//get the user ID / Student ID field
		for(Student::const_iterator field = course->m_fields.begin(); field != course->m_fields.end(); ++field)
		{
			string f = *field;
			if (f.compare("Student Id") == 0 || f.compare("User ID") == 0) {
				break;
			}
			else idField++;
		}

		//iterating through the students
		for(vector<Student>::const_iterator student = course->m_students.begin(); student != course->m_students.end(); ++student)
		{
			Student s = *student;

			//checking every student ID for a match
			if (s[idField].compare(studentID) == 0)
			{

				if (newData.size() == 0) newData.push_back(s[idField]); //first entry of the created csv is always the id
				if (newFields.size() == 0) newFields.push_back("User ID");

				//get iterators for the fields and for the data
				Student::const_iterator sit = s.begin();
				Student::const_iterator f = course->m_fields.begin();

				//we can iterate through both vectors together since the fields and data should always match at a given index
				while ((sit != s.end()) && (f != course->m_fields.end()))
				{
					string fval = *f; //current header title
					std:transform(fval.begin(), fval.end(), fval.begin(), ::tolower); //makes fval lower case for more accurate checking

					//we only keep the fields that aren't related to the names and user ids
					if (fval.find("name") == string::npos && fval.find("student id") == string::npos && fval.find("user id") == string::npos)
					{
						stringstream ss;
						//building new header titles in the form courseName-semester-year-title
						ss << courseName << "-" << semester << "-" << year << "-" << *f;
						string sout = ss.str();
						sout.erase(remove(sout.begin(), sout.end(), '\r'), sout.end()); //removes newlines
						newFields.push_back(sout);
						ss.str("");

						string dout = *sit;
						dout.erase(remove(dout.begin(), dout.end(), '\r'), dout.end()); //removes newlines
						
						newData.push_back("\""+dout+"\"");

					}

					f++;
					sit++;

				}
			}
		}
	}
	
	if (newData.size() == 0) {
		cout << "No match found for student " << studentID << endl;
		return;
	}

	//writing out


	ofstream outfile((saveLocation).c_str());

	int ctr = 0;

	//writing the fields
	for (vector<string>::const_iterator fw = newFields.begin(); fw != newFields.end(); ++fw) {
		outfile << *fw;
		if (ctr != newFields.size()-1) outfile << ",";
		ctr++;
	}
		ctr = 0;
		outfile << endl;

	//writing the data
	for (vector<string>::const_iterator dr = newData.begin(); dr != newData.end(); ++dr) {
		outfile << *dr;
		if (ctr != newData.size()-1) outfile << ",";
		ctr++;
	}
	outfile.close();
	cout << "Exported student " << studentID << " to " << saveLocation << endl;
//.........这里部分代码省略.........
开发者ID:maribelCS,项目名称:gradesDataIntegration,代码行数:101,代码来源:Gradebook.cpp


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