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

相关内容

热门资讯

黑科技好友房“wepoke透明... 黑科技好友房“wepoke透明黑科技”wepoke透明挂咋测试(ai代打)原来有挂(有挂方法)-哔哩...
带你了解"aapok... 带你了解"aapokerai辅助"aapoker辅助工具ai(真是是有挂)-哔哩哔哩1、许多玩家不知...
必备科技(德州ai辅助神器软件... 必备科技(德州ai辅助神器软件)德州之星外挂(最初是真的有挂)-哔哩哔哩;支持多人共享记分板与复盘,...
必备辅助推荐“wpk到底有没有... 1、必备辅助推荐“wpk到底有没有外挂”wpk ai辅助购买渠道(WPK)一直真的是有挂(有挂讲解)...
黑科技神器“wepokeai代... 黑科技神器“wepokeai代打”wepoke透明挂软件(ai辅助)其实真的有挂(的确有挂)-哔哩哔...
总算了解"aapok... 总算了解"aapoker发牌机制"aapoker猫腻(总是真的是有挂)-哔哩哔哩1、aapoker发...
推荐几款新版(德州ai人工智能... 推荐几款新版(德州ai人工智能)德州之星辅助软件介绍(真是真的是有挂)-哔哩哔哩是一款可以让一直输的...
玩家必知教程!“wpk最新黑科... 玩家必知教程!“wpk最新黑科技”wpk ai辅助(wPK)好像真的有挂(有挂方式)-哔哩哔哩;wp...
黑科技攻略“wepoke有没有... 黑科技攻略“wepoke有没有挂”wepoke透视挂靠谱吗(透明挂黑科技)总是是真的有挂(有挂技术)...
揭秘"aapoker... 揭秘"aapoker辅助工具ai"aapoker透明挂下载(切实有挂)-哔哩哔哩1、aapoker透...