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、打开软件启...
最新消息!aapoker脚本(... 最新消息!aapoker脚本(透视)hhpoker辅助挂下载-本来有挂(哔哩哔哩)一、hhpoker...
透视软件!微乐家乡小程序辅助,... 透视软件!微乐家乡小程序辅助,微乐小程序免费黑科技,攻略教程(有挂神器)-哔哩哔哩运微乐小程序免费黑...
据通报!pokerworld修... 据通报!pokerworld修改器(透视)竞技联盟破解版最新版-竟然真的是有挂(哔哩哔哩)1、在竞技...
此事迅速冲上热搜!微信微乐辅助... 此事迅速冲上热搜!微信微乐辅助ios,微乐小程序免费黑科技,绝活儿教程(有挂平台)-哔哩哔哩1、玩家...
黑科技辅助挂!德普之星私人局辅... 黑科技辅助挂!德普之星私人局辅助器(透视)德普之星辅助工具如何打开-原来是真的挂(哔哩哔哩)1、德普...
透视游戏!wpk软件是正规的吗... 透视游戏!wpk软件是正规的吗(透视)如何判断wpk辅助软件的真假-总是真的是有挂(哔哩哔哩)1、如...
透视玄学!微信小程序微乐辅助免... 透视玄学!微信小程序微乐辅助免费版,微乐小程序免费黑科技,方案教程(有挂辅助器)-哔哩哔哩微信小程序...
2026版教程!aapoker... 2026版教程!aapoker插件下载(透视)hhpoker德州真的假的-竟然真的是有挂(哔哩哔哩)...
于此同时!微乐游戏小程序辅助器... 于此同时!微乐游戏小程序辅助器免费,微乐小程序免费黑科技,妙招教程(有挂修改器)-哔哩哔哩1、游戏颠...