0
我想在關閉程序後創建保存數據的動物數據庫。所以我認爲它應該保存在一個文本文件中。C++中簡單的數據庫文本文件
1)是否有一個已經制作的C++函數?
2)如果不是,我們該如何解決問題?
到現在爲止,我有這樣的:
#include <iostream>
#include <string>
class Animal {
public:
std::string name, color1, color2, race, notes;
int age;
};
void writeInTheDatabase(Animal const& ani);
int readAgeFromTheDataBase(Animal const& ani);
int main() {
Animal cat1;
cat1.name = "silvester";
cat1.color1 = "black";
cat1.color2 = "white";
cat1.age = 4;
Animal dog1;
dog1.name = "Arnold";
dog1.color1 = "brown";
dog1.color2 = "black";
dog1.age = 3;
writeInTheDatabase(dog1);
std::cout << "the age is: " << readAgeFromTheDataBase(dog1) << std::endl;
}
void writeInTheDatabaseTextFile(Animal const& ani) {
// this function should put all the info in a text file
}
int readAgeFromTheDataBase(Animal const& ani) {
int age;
// this function should return the age of an animal given
return age;
}
那究竟是什麼問題? – Mureinik
@Mureinik AFAICT他問「是否已經有預定義的功能」。到OP:見http://en.cppreference.com/w/ – sehe
「動物」是誤導,因爲它似乎一次只包含一個動物。它也應該是「物種」而不是「種族」。 – tadman