代码:
using std::map;
using std::ofstream;
using std::ifstream;
map<int, int> m = { ... }; // 待存储的map m
// 存入文件out.txt
ofstream of("out.txt");
for (const auto &i : m) {
of << i.first << ' ' << i.second << std::endl;
}
代码:
using std::map;
using std::ofstream;
using std::ifstream;
map<int, int> m = { ... }; // 待存储的map m
// 存入文件out.txt
ofstream of("out.txt");
for (const auto &i : m) {
of << i.first << ' ' << i.second << std::endl;
}