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、有没有辅助教程、有透...
大家学习交流!微乐小程序自建房... 大家学习交流!微乐小程序自建房辅助!微乐小程序游戏破解器(都是存在有辅助脚本)1、每一步都需要思考,...
终于知道!微乐小程序自建房辅助... 终于知道!微乐小程序自建房辅助!微乐小程序自建房透视下载(确实有辅助脚本)该软件可以轻松地帮助玩家将...
一分钟教会你!微乐小程序辅助工... 一分钟教会你!微乐小程序辅助工具!微乐小程序辅助开发(都是真的是有辅助工具)1、玩家可以在线上大神俱...
玩家必备攻略!微乐小程序自建房... 玩家必备攻略!微乐小程序自建房辅助!微信小程序微乐辅助器教程(真是是真的有辅助技巧)所有人都在同一条...
技巧知识分享!微乐小程序自建房... 技巧知识分享!微乐小程序自建房辅助!微乐斗地主有挂吗(好像是有辅助攻略)1、进入到是否有挂之后,能看...
推荐攻略!微乐小程序辅助工具!... 推荐攻略!微乐小程序辅助工具!微乐自建房辅助下载(总是真的有辅助软件)1、脚本辅助下载、免费透视脚本...
总算清楚!微乐小程序自建房辅助... 总算清楚!微乐小程序自建房辅助!微信小程序多乐辅助器(原来是真的有辅助器)透视方法中分为三种模型:靠...
教程攻略!微乐小程序自建房辅助... 教程攻略!微乐小程序自建房辅助!微信微乐游戏苹果辅助器(都是真的有辅助攻略)一、游戏安装教程牌型概率...