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辅助”开... 两分钟辅助“拼十app辅助”开挂(透视)辅助挂总结教程-知乎;无需打开直接搜索加薇136704302...
教程辅助“指尖四川辅助破解版苹... 教程辅助“指尖四川辅助破解版苹果”开挂(透视)辅助安装-知乎《详细加薇136704302咨询》游戏特...
重大发现“白金岛放炮罚作弊码有... 白金岛放炮罚作弊码有哪些是一款可以让一直输的玩家,快速成为一个“必胜”的ai辅助神器,有需要的用户可...
三分钟辅助“情怀蒲仙辅助”开挂... 情怀蒲仙辅助 无需打开直接搜索微信:136704302本司针对手游进行,选择我们的四大理由: 1、软...
教程辅助“jj斗地主麻将外卦挂... 教程辅助“jj斗地主麻将外卦挂”开挂(透视)辅助插件-哔哩哔哩 了解更多开挂安装加(13670430...
玩家必看教程“闽乐乐辅助器免费... 闽乐乐辅助器免费版是一款专注玩家量身打造的游戏记牌类型软件,在闽乐乐辅助器免费版这款游戏中我们可以记...
一分钟辅助“wepoker透视... >>您好:wepoker透视脚本是什么确实是有挂的,很多玩家在这款wepoker透视脚本是什么游戏中...