c++向文件中写入和读取数据。要includ和
ofstream savefile;
savefile.open(“D:\forfun\boundary”);
for(map<int,vector>::const_iterator miter = myMap.begin();miter != myMap.end();miter++)
{
cout<first<<endl;
cout<<myMap[miter->first][0]<<" “<<myMap[miter->first][1]<<endl;
savefile<first;
savefile<<”\t";
savefile<<myMap[miter->first][0];
savefile<<"\t";
savefile<<myMap[miter->first][1];
savefile<<"\n";
}
savefile.close();
ifstream getfile;
getfile.open(“D:\forfun\boundary”);
string strone;
cout<<“get from file”<<endl;
map<int,vector> mapGet;
while(getline(getfile,strone))
{
stringstream ss;
ss<<strone;
int a;
double b;
double c;
ss>>a>>b>>c;
mapGet[a].push_back(b);
mapGet[a].push_back©;
cout<<a<<" “<<b<<” "<<c<<endl;
}