我已按照网上的说明进行操作,此代码假设将输入添加到文件“数据库”的末尾。但是当我检查时,数据会覆盖现有数据。请帮忙,这是我的代码:
int main(){
string name;
string address;
string handphone;
cout << "Name: ";
getline(cin, name);
cout << "Address: ";
getline(cin, address);
cout << "Handphone Number: ";
getline(cin, handphone);
ofstream myfile("database", ios_base::ate);
myfile.seekp( 0, ios_base::end );
myfile << name<<endl;
myfile << address<<endl;
myfile << handphone<<endl;
myfile.close();
}