我正在尝试使用地图将数据安全地归档,但我不知道如何。我想将学生的姓名和年龄保存到文件中,然后当我查找学生的姓名时,它应该显示他们的年龄。
#include <iostream>
#include <map>
#include <fstream>
#include <string>
using namespace std;
class student {
private:
map<int, string> map;
public:
void students(string name, int age);
};
void students(string name, int age) {
if (age < 1) {
cout << "You must enter a positive number." << endl;
return;
}
}
void main() {
ofstream filemap;
filemap.open("map.txt");
int age;
string name;
cout << "Please enter the name : " << endl;
cin >> name;
cout << "Please enter the age : " << endl;
cin >> age;
// code to save map to file
filemap.close();
}