文件输入,问什么每次都只剩下最后一次写入的

int main(){
for(int k=0;k<m;k++){
AddEdge(graph,rand()%n,rand()%n);
}
}
void AddEdge(Graph *graph,int v1, int v2)//加边
{
ofstream ocout;
ocout.open("city.txt");
if (v1 == v2){
cout<<"冗余边"<<v1<<" "<<v2<<endl;

ocout<<"冗余边"<<v1<<"  "<<v2<<endl;

    return;
}

}
应该怎么改啊,还没学文件

ofstream ocout;

void AddEdge(int v1, int v2)//加边 
{ 
    ocout.seekp(0, ios_base::end);
    cout<<"冗余边"<<v1<<" "<<v2<<endl; 
    ocout<<"冗余边"<<v1<<" "<<v2<<endl;

}

int main()
{ 
    ocout.open("city.txt");
    for(int k=0;k<10;k++)
    { 
        AddEdge(rand()%5,rand()%5); 
    } 
    ocout.close();
} 

我只知道java流里边可以设置append.C就不清楚了