自己用map容器存儲了一些東西,不知道如何寫入文件,而且需要讀取文件中的內(nèi)容!?。?
2 回答

onemoo
TA貢獻883條經(jīng)驗 獲得超454個贊
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; } //?讀取文件,存入map?m2中 map<int,?int>?m2; ifstream?if("out.txt"); int?key,?value; while?(if?>>?key?>>?value)?{ ????m2[key]?=?value; }
- 2 回答
- 0 關(guān)注
- 5675 瀏覽
添加回答
舉報
0/150
提交
取消