栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

c++ mac替换冒号以及文件写入

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c++ mac替换冒号以及文件写入

#include 
#include 
#include 
#include 
#include 
#include 
#include   
#include 
using namespace std;

string& replace_all(string& str, const string& old_value, const string& new_value)
{
	for(string::size_type pos(0); pos!=string::npos; pos+=new_value.length()) 
	{
		if( (pos=str.find(old_value,pos))!=string::npos )
		str.replace(pos,old_value.length(),new_value);
		else break ;
	}
	return str;
}

int main() {
	string macAddress = "00:11:22:33:44:55";
	macAddress = replace_all(macAddress,":","");
	time_t currentTime = time(NULL);
	char chCurrentTime[256];
	strftime(chCurrentTime,sizeof(chCurrentTime),"%Y%m%d",localtime(¤tTime));
	string stCurrentTime = chCurrentTime;
	string path = stCurrentTime;
	cout << path << endl;
	if(0 != _access(path.c_str(),0)) 
	{
		int flag = _mkdir(path.c_str());
		if (flag == 0) {
			cout << "success" << endl;
		} else {
			cout << "fail" << endl;
		}
	} 
	char chCurrentTime1[256];
	strftime(chCurrentTime1,sizeof(chCurrentTime),"%Y-%m %d %H:%M:%S",localtime(¤tTime));
	string stCurrentTime1 = chCurrentTime1;
	
	
	cout << _pgmptr << endl;
	ofstream outfile;
   	outfile.open(".\"+stCurrentTime+"\"+macAddress,ios::app|ios::in|ios::out);
   	
   	outfile << stCurrentTime1 << endl;
   	outfile << 1234 << endl;
   	
   	
   	
   	outfile.close();
	return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/429913.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号