c++写数据结构进入文件
创始人
2025-01-09 02:30:00
0

以下定义一个数据结构

struct SData { 	std::string url; 	int number; 	std::string memo; }; 

写入文件

void StorageDataToFile(const std::string& filename, const SData& data) {    std::ofstream outFile(filename);    if (outFile.is_open()) {    	// 使用std::stringstream格式化数据    	std::stringstream ss;    	ss << data.url << "," << data.member << "," << data.memo << "\n";    	// 将格式化后的字符串写入文件    	outFile << ss.str();     	outFile.close();    	AfxMessageBox(L"ok storage") ;    }    else {    	AfxMessageBox(L"error");    } } 

读取

UserData ReadDataFromFile(const std::string& filename) { 	SData data; 	std::ifstream inFile(filename); 	if (inFile.is_open()) { 		std::string line; 		getline(inFile, line); 		std::istringstream iss(line); 		if (iss >> data.url>> data.number >> data.memo) { 			inFile.close(); 			return userData; 		} 		else { 			AfxMessageBox(L"error"); 		} 	} 	else { 		AfxMessageBox(L"error"); 	}  	// 如果读取失败,返回默认构造的UserData 	return UserData(); } 

相关内容

热门资讯

分享透视!智星德州插件,拱趴大... 分享透视!智星德州插件,拱趴大菠萝有挂吗(透视)真是是有辅助app(哔哩哔哩)1、操作简单,无需拱趴...
最终!pokemmo手机辅助软... 最终!pokemmo手机辅助软件,新九天作必弊系统,资料辅助插件(有挂教程)-哔哩哔哩1、pokem...
经调查!福建十三兵修改器,一贯... 经调查!福建十三兵修改器,一贯存在有辅助神器(有挂透明挂)-哔哩哔哩1、福建十三兵修改器公共底牌简单...
分享透视!红龙poker辅助器... 分享透视!红龙poker辅助器免费观看,智星菠萝辅助(透视)总是有辅助工具(哔哩哔哩)运红龙poke...
透视挂!cloudpoker作... 透视挂!cloudpoker作必弊,决胜游戏辅助器,操作辅助挂(真实有挂)-哔哩哔哩1、完成决胜游戏...
经核实!广西老友玩有破解码,果... 经核实!广西老友玩有破解码,果然真的有辅助器(有挂方式)-哔哩哔哩1、操作简单,无需广西老友玩有破解...
开挂透视!拱趴大菠萝作必弊方法... 开挂透视!拱趴大菠萝作必弊方法,pokemmo辅助脚本(透视)果然是真的有辅助神器(哔哩哔哩)1、许...
反观!天天贵阳游戏辅助,确实是... 反观!天天贵阳游戏辅助,确实是真的辅助修改器(真的有挂)-哔哩哔哩1、每一步都需要思考,不同水平的挑...
无独有偶!聚星ai辅助工具下载... 无独有偶!聚星ai辅助工具下载,微信小程序雀神挂件价格,资料辅助app(有挂细节)-哔哩哔哩所有人都...
透视科技!拱趴大菠萝万能挂,哈... 透视科技!拱趴大菠萝万能挂,哈糖大菠萝破解器,操作辅助技巧(果真有挂)-哔哩哔哩该软件可以轻松地帮助...