#include <fstream>
#include <iostream>
using namespace std;
class Country {
public:
string country;
int number;
char grade;
Country(string inputCountry, int inputNumber, char inputGrade) {
country = inputCountry;
number = inputNumber;
grade = inputGrade;
cout << "Country : " << country << endl;
cout << "Number : " << number << endl;
cout << "Grade : " << grade << endl;
}
string stringify() {
return country + " " + to_string(number) + " " + grade + " "; // Convert 'number' to string using to_string()
}
};
class dataBase {
public:
ifstream in;
ofstream out;
string fileName;
dataBase(const char* fileName) {
fileName = fileName;
}
void write(Country data) {
cout << "Country : " << data.country << endl;
cout << "Number : " << data.number << endl;
cout << "Grade : " << data.grade << endl;
out.open(fileName, ios::app);
out << data.stringify() << endl;
}
};
int main() {
Country indonesia = Country("Indonesia", 71, 'C');
dataBase dataBaseCountry = dataBase("latihanDatabase.txt");
// Code to save data from 'indonesia' to the file 'country.txt'
dataBaseCountry.write(indonesia);
return 0;
}```
i cant save output to txt file
#cant save file
2 messages · Page 1 of 1 (latest)