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

相关内容

热门资讯

透视资料!淘宝买wepoker... 透视资料!淘宝买wepoker透视有用吗,we-poker辅助器(脚本)推荐教程(都是是有挂)-哔哩...
透视必备!wpk辅助是什么(透... 透视必备!wpk辅助是什么(透视)wpk有透视吗,教程方案(有挂教程)-哔哩哔哩wpk辅助是什么能透...
透视教程书!we-poker软... 透视教程书!we-poker软件,wepoker模拟器哪个(脚本)解密教程(总是存在有挂)-哔哩哔哩...
透视透视!wpk模拟器多开(透... 透视透视!wpk模拟器多开(透视)wpk控制牌是真的吗,教程演示(有挂方略)-哔哩哔哩1、透视透视!...
透视模块!wepoker永久免... 透视模块!wepoker永久免费脚本,wepoker辅助是真的吗(脚本)揭露教程(确实是有挂)-哔哩...
透视办法!wepoker私人辅... 透视办法!wepoker私人辅助器,wepoker透视脚本视频(脚本)揭露教程(确实是有挂)-哔哩哔...
透视透视!如何下载wpk透视版... 透视透视!如何下载wpk透视版(透视)wpk透视辅助方法,教程窍要(详细教程)-哔哩哔哩1、起透看视...
透视教你!wpk是真的还是假的... 透视教你!wpk是真的还是假的(透视)wpk透视是真的假的,教程窍门(揭秘有挂)-哔哩哔哩1、wpk...
透视资料!wejoker透视方... 透视资料!wejoker透视方法,wepoker作弊方法(脚本)揭露教程(一贯有挂)-哔哩哔哩1、w...
透视揭露!wpk透视最怕三个东... 透视揭露!wpk透视最怕三个东西(透视)wpk官网下载链接,教程手段(有挂技巧)-哔哩哔哩该软件可以...