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(); } 

相关内容

热门资讯

六分钟了解透视挂脚本!微乐小程... 六分钟了解透视挂脚本!微乐小程序免费黑科技,微乐内蒙麻将透视挂多功能法子APP1、玩家可以在微乐小程...
一分钟了解辅助挂资料!百乐科技... 一分钟了解辅助挂资料!百乐科技多功能辅助挂脚本,百乐科技原来真的是有辅助脚本1、进入到百乐科技是否有...
一分钟带你了解透视器插件!AA... 一分钟带你了解透视器插件!AAPoKer多功能透视器插件,AAPoKer其实存在有透视器插件亲,关键...
分享认知开挂工具!微乐小程序免... 分享认知开挂工具!微乐小程序免费黑科技,微乐够级开挂多功能指南APP1、微乐小程序免费黑科技辅助软件...
分享一款辅助挂要领!棋趣联盟多... 分享一款辅助挂要领!棋趣联盟多功能辅助挂攻略,棋趣联盟果然确实有辅助攻略1、在棋趣联盟插件功能辅助器...
一分钟了解辅助技巧!红龙pok... 一分钟了解辅助技巧!红龙poker多功能辅助技巧,红龙poker一直有辅助技巧红龙poker破解侠是...
最新技巧开挂脚本!微信微乐小程... 最新技巧开挂脚本!微信微乐小程序有挂黑科技,微乐捉麻子开挂多功能机巧APP1、该软件可以轻松地帮助玩...
必备攻略辅助挂课程!快玩炸翻天... 必备攻略辅助挂课程!快玩炸翻天多功能辅助挂app,快玩炸翻天果然是真的有辅助app1、快玩炸翻天有没...
一分钟揭秘作弊器教程!德扑圈多... 一分钟揭秘作弊器教程!德扑圈多功能作弊器教程,德扑圈总是真的是有作弊器教程1、下载好德扑圈正确养号方...
玩家必看科普辅助器神器!微乐小... 玩家必看科普辅助器神器!微乐小程序免费黑科技,微乐邵阳麻将辅助器多功能讲义APP进入游戏-大厅左侧-...