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

#include <iostream>
#include <string>
#include <direct.h>
#include <io.h>
#include <time.h>
#include <fstream>
#include <stdlib.h>  
#include <stdio.h>
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(&currentTime));
	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(&currentTime));
	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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值