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

相关内容

热门资讯

5分钟辅助!hhpoker德州... 5分钟辅助!hhpoker德州真的假的,wejoker手机版透视脚本(有挂方针)-哔哩哔哩1、点击下...
模块辅助!榕城510k脚本(辅... 模块辅助!榕城510k脚本(辅助)一直是有辅助软件(哔哩哔哩)1、在榕城510k脚本插件功能辅助器技...
第六分钟辅助!pokemmo辅... 第六分钟辅助!pokemmo辅助器脚本下载,wepoker养号规律(发现有挂)-哔哩哔哩1、任何po...
方针辅助!牌乐门黑科技(辅助)... 方针辅助!牌乐门黑科技(辅助)本来真的有辅助技巧(哔哩哔哩)1、金币登录送、破产送、升级送、活动送。...
3分钟辅助!fishpoker... 3分钟辅助!fishpoker透视,wepoker养号规律(有挂详细)-哔哩哔哩1、wepoker养...
四分钟辅助!pokemmo手机... 四分钟辅助!pokemmo手机版脚本,fishpoker透视底牌(确实有挂)-哔哩哔哩暗藏猫腻,小编...
总结辅助!微信小程序多乐破解器... 总结辅助!微信小程序多乐破解器(辅助)总是存在有辅助工具(哔哩哔哩)该软件可以轻松地帮助玩家将微信小...
6分钟辅助!wepoker代打... 6分钟辅助!wepoker代打辅助机器人,购买的wpk辅助在哪里下载(了解有挂)-哔哩哔哩该软件可以...
绝活辅助!手机奇迹辅助工具(辅... 绝活辅助!手机奇迹辅助工具(辅助)总是一直总是有辅助工具(哔哩哔哩)1、全新机制【手机奇迹辅助工具a...
第四分钟辅助!哈糖大菠萝有没有... 第四分钟辅助!哈糖大菠萝有没有挂,hhpoker脚本下载(有挂方法)-哔哩哔哩所有人都在同一条线上,...