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

相关内容

热门资讯

透视免费!wepoker数据分... 透视免费!wepoker数据分析,潮友会辅助器,其实有挂(解谜透明挂教程)-哔哩哔哩1、打开软件启动...
透视胜率!hhpoker有没有... 透视胜率!hhpoker有没有辅助(透视)开挂辅助器(好像有挂)-哔哩哔哩hhpoker有没有辅助辅...
目前!兴动互娱辅助工具靠谱吗,... 目前!兴动互娱辅助工具靠谱吗,杭州都莱辅助软件,黑科技教程(原来是有挂)-哔哩哔哩1、进入到兴动互娱...
透视教程!aapoker怎么控... 透视教程!aapoker怎么控制牌,菠萝辅助器免费版的功能介绍,教材教程(原来真的有挂)-哔哩哔哩一...
刚刚!wepoker一直输的号... 刚刚!wepoker一直输的号能继续打吗,兴动互娱辅助脚本ios下载,好像真的是有挂(推荐AI教程)...
透视辅助!aapoker辅助器... 透视辅助!aapoker辅助器怎么用(透视)开挂辅助工具(确实真的是有挂)-哔哩哔哩1、每一步都需要...
透视模拟器!wepoker高级... 透视模拟器!wepoker高级辅助,hhpoker脚本,办法教程(切实真的有挂)-哔哩哔哩小薇(透视...
针对!广东闲来辅助免费,wep... 针对!广东闲来辅助免费,wepoker辅助工具,技巧教程(好像是真的挂)-哔哩哔哩1、广东闲来辅助免...
透视新版!德州局透视脚本免费版... 透视新版!德州局透视脚本免费版下载手机版,aapoker能控制牌吗,教材教程(切实有挂)-哔哩哔哩1...
据权威媒体报道!wepoker... 据权威媒体报道!wepoker辅助脚本,福建相约十三张破解,其实有挂(必备微扑克教程)-哔哩哔哩1)...