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

相关内容

热门资讯

透视窍要!agpoker辅助(... 透视窍要!agpoker辅助(透视)本来存在有辅助软件(哔哩哔哩)1、透视窍要!agpoker辅助(...
详细透视!epoker有透视吗... 详细透视!epoker有透视吗,哈糖大菠萝开挂(透视)总是是真的有辅助方法(哔哩哔哩)1、玩家可以在...
透视操作!约局吧开挂(透视)本... 您好,约局吧开挂这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多玩家在这...
了解透视!德州透视脚本,哈糖大... 了解透视!德州透视脚本,哈糖大菠萝有挂吗5个常用方法(透视)确实是真的有辅助技巧(哔哩哔哩)1、哈糖...
透视方针!hhpoker必备开... 透视方针!hhpoker必备开挂(透视)竟然存在有辅助平台(哔哩哔哩)1、首先打开hhpoker必备...
详细透视!德州局透视脚本免费版... 详细透视!德州局透视脚本免费版下载手机版,pokemmo脚本手机版(透视)确实是有辅助攻略(哔哩哔哩...
透视法门!菠萝辅助器免费版的特... 透视法门!菠萝辅助器免费版的特点(透视)都是是有辅助平台(哔哩哔哩)在进入菠萝辅助器免费版的特点软件...
解谜透视!拱趴大菠萝万能辅助器... 您好,拱趴大菠萝万能辅助器这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很...
透视教材!wepoker好友局... 透视教材!wepoker好友局透视(透视)竟然真的是有辅助神器(哔哩哔哩)在进入wepoker好友局...
专业透视!fishpoker透... 专业透视!fishpoker透视底牌,xpoker怎么作必弊(透视)一贯真的有辅助app(哔哩哔哩)...