32 lines
843 B
C++
32 lines
843 B
C++
#include "db.h"
|
|
#include <fstream>
|
|
#include <iostream>
|
|
|
|
bool exportData(const std::string& filename, const std::vector<Student>& students) {
|
|
std::ofstream file(filename);
|
|
if(!file.is_open()) return false;
|
|
|
|
for(auto& s : students){
|
|
file << s.nom << " " << s.notes[0] << " " << s.notes[1] << " " << s.notes[2] << "\n";
|
|
}
|
|
file.close();
|
|
return true;
|
|
}
|
|
|
|
bool importData(const std::string& filename, std::vector<Student>& students) {
|
|
std::ifstream file(filename);
|
|
if(!file.is_open()) return false;
|
|
|
|
std::string nom;
|
|
int n1,n2,n3;
|
|
int i = 0;
|
|
while(file >> nom >> n1 >> n2 >> n3 && i < students.size()){
|
|
students[i].nom = nom;
|
|
students[i].notes[0] = n1;
|
|
students[i].notes[1] = n2;
|
|
students[i].notes[2] = n3;
|
|
i++;
|
|
}
|
|
file.close();
|
|
return true;
|
|
} |