fstream

c++ fstream - creating own formatting flags

大城市里の小女人 提交于 2020-05-29 03:23:34
问题 i need to create new flags for the format of the output file. i have a class class foo{ bar* members; ofstream& operator<<(ofstream&); ifstream& operator>>(ifstream&); }; and i want to use it like: fstream os('filename.xml'); foo f; os << xml << f; os.close(); this will save an xml file. fstream os('filename.json'); foo f; os << json << f; os.close(); and this an json file. How can i do this? 回答1: You can easily create yor own manipulators, either hijacking an existing flag or using std::ios

c++ fstream - creating own formatting flags

…衆ロ難τιáo~ 提交于 2020-05-29 03:22:37
问题 i need to create new flags for the format of the output file. i have a class class foo{ bar* members; ofstream& operator<<(ofstream&); ifstream& operator>>(ifstream&); }; and i want to use it like: fstream os('filename.xml'); foo f; os << xml << f; os.close(); this will save an xml file. fstream os('filename.json'); foo f; os << json << f; os.close(); and this an json file. How can i do this? 回答1: You can easily create yor own manipulators, either hijacking an existing flag or using std::ios

c++ fstream - creating own formatting flags

跟風遠走 提交于 2020-05-29 03:22:06
问题 i need to create new flags for the format of the output file. i have a class class foo{ bar* members; ofstream& operator<<(ofstream&); ifstream& operator>>(ifstream&); }; and i want to use it like: fstream os('filename.xml'); foo f; os << xml << f; os.close(); this will save an xml file. fstream os('filename.json'); foo f; os << json << f; os.close(); and this an json file. How can i do this? 回答1: You can easily create yor own manipulators, either hijacking an existing flag or using std::ios