2
나는 그물에 지시를 따르고이 부호는 파일 "데이타베이스"의 끝에 입력을 추가 한 것을 가정하고있다. 그러나 내가 확인할 때, 데이터는 기존 데이터를 타고 넘어 간다.C++에서 파일 끝에 데이터를 어떻게 추가합니까?
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();
}
_stream_ 열기 모드에 'out'을 추가하십시오 ... –
[C++ Ofstream Overwriting] [1]에 대한 답변에 따라 instream 플래그에서 ios :: app을 사용해야합니다. [1] : http://stackoverflow.com/questions/8220196/c-ofstream-overwriting –