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

相关内容

热门资讯

7分钟了解!wepoker免费... 7分钟了解!wepoker免费透视脚本(脚本)果然有辅助神器(哔哩哔哩)1、打开软件启动之后找到中间...
7分钟烘培!蜀山四川小程序技巧... 7分钟烘培!蜀山四川小程序技巧(外挂)确实真的有辅助教程(哔哩哔哩)亲,关键说明,蜀山四川小程序技巧...
技巧辅助挂!竹间茶馆作必弊码&... 技巧辅助挂!竹间茶馆作必弊码"果然真的是有辅助挂"(哔哩哔哩);该软件可以轻松地帮助玩家将竹间茶馆作...
第2分钟了解!大菠萝手游辅助(... 您好,大菠萝手游辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多玩家...
4分钟手册!光明辅助器(外挂)... 4分钟手册!光明辅助器(外挂)一贯是有辅助技巧(哔哩哔哩)1、实时光明辅助器透视辅助更新:用户可以随...
第二分钟了解!wepoker有... 第二分钟了解!wepoker有没有挂(脚本)真是是有辅助器(哔哩哔哩)1、wepoker有没有挂辅助...
在玩家背景下!潘潘讲故事辅助器... 在玩家背景下!潘潘讲故事辅助器"真是确实有辅助脚本"(哔哩哔哩)1、潘潘讲故事辅助器辅助软件下载优化...
第7分钟方案!熊猫四川游戏透视... 第7分钟方案!熊猫四川游戏透视辅助(外挂)真是一直总是有辅助软件(哔哩哔哩)1、该软件可以轻松地帮助...
第六分钟了解!wepoker有... 第六分钟了解!wepoker有没有插件(脚本)都是存在有辅助软件(哔哩哔哩)一、wepoker有没有...
迎来新发展!科乐天天踢有没有挂... 您好,科乐天天踢有没有挂作必弊这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302...