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、起透看视...
透视有挂!wpk透视辅助(透视... 透视有挂!wpk透视辅助(透视)都是是真的辅助下载(有挂工具)-哔哩哔哩1、该软件可以轻松地帮助玩家...
一分钟了解!wepoker透视... 一分钟了解!wepoker透视方法,新518互游脚本,一直真的有辅助透视(有挂神器)1、实时新518...
外挂绝活!拱趴大菠萝万能挂图解... 外挂绝活!拱趴大菠萝万能挂图解,约局吧辅助器-竟然是真的有辅助插件(哔哩哔哩)拱趴大菠萝万能挂图解透...
透视攻略!wepoker网页版... 透视攻略!wepoker网页版透视方法(透视)其实存在有辅助平台(有挂方略)-哔哩哔哩wepoker...
最新研发!wepoker安装教... 最新研发!wepoker安装教程,黑桃a3哟西破解版,好像有辅助辅助(确实有挂)1、该软件可以轻松地...
外挂大纲!菠萝德普辅助器免费版... 外挂大纲!菠萝德普辅助器免费版在哪里,红龙poker有辅助吗-总是是有辅助脚本(哔哩哔哩)1、菠萝德...
据玩家消息!werplan外卦... 据玩家消息!werplan外卦神器(透视)都是是真的辅助神器(有挂透视)-哔哩哔哩1)werplan...
今日科普!wepoker透视脚... 今日科普!wepoker透视脚本免费,789大菠萝可以控制吗,果然存在有辅助神器(有挂讲解)1、任何...
外挂总结!佛手在线大菠萝为什么... 外挂总结!佛手在线大菠萝为什么都输,pokermaster脚本-总是一直都是有辅助app(哔哩哔哩)...