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

相关内容

热门资讯

1分钟外挂!wepoker新号... 1分钟外挂!wepoker新号好一点吗(透视)总是是真的挂,必备教程(详细教程)-哔哩哔哩1、完成w...
透视辅助!hhpoker有没有... 透视辅助!hhpoker有没有辅助挂(透视)本来有挂,新2025版(有挂插件)-哔哩哔哩1、不需要A...
透视讲解!hhpoker德州透... 透视讲解!hhpoker德州透视,epoker透视底牌,策略教程(有挂教程)-哔哩哔哩1、不需要AI...
4分钟曝光!xpoker辅助助... 4分钟曝光!xpoker辅助助手(透视)总是有挂,解密教程(有挂细节)-哔哩哔哩1)xpoker辅助...
透视代打!wpk透视插件,hh... 透视代打!wpk透视插件,hhpoker软件靠谱吗,学习教程(有挂讲解)-哔哩哔哩1、hhpoker...
透视黑科技!hhpoker透视... 透视黑科技!hhpoker透视方法(透视)一直真的是有挂,详细教程(有挂德州)-哔哩哔哩1、hhpo...
6分钟普及!epoker免费透... 6分钟普及!epoker免费透视脚本(透视)原来是有挂,我来教教你(有人有挂)-哔哩哔哩1、epok...
透视了解!wepoker怎么买... 透视了解!wepoker怎么买辅助(透视)本来有挂,细节揭秘(有挂脚本)-哔哩哔哩1、透视了解!we...
透视总结!wepoker辅助真... 透视总结!wepoker辅助真的假的,约局吧开挂神器是真的吗,绝活儿教程(有挂方略)-哔哩哔哩透视总...
透视实锤!拱趴大菠萝机器人(透... 透视实锤!拱趴大菠萝机器人(透视)一直是有挂,解说技巧(有挂机制)-哔哩哔哩小薇(透视辅助)致您一封...