#include<string>#include<sstream>usingnamespace std;
string int2stringAdd0(int num,int max_num){int length = std::to_string(max_num).size();
stringstream ss;
ss <<setw(length)<<setfill('0')<< num ;
string str;
ss >> str;return str;}
创建目录
#include<string>usingnamespace std;boolcreateDirectorys(string path){
string cmd("mkdir -p "+ path);int ret =system(cmd.c_str());if(ret){
cout <<"error when create directories : "<< ret <<", :"<<strerror(errno)<< endl;return0;}
cout <<"successfully create directories: "<< path << endl;return1;}
生成随机数
#include<time.h>#include<stdlib.h>intrandMin2Max(int min,int max){srand(time(0));int num =rand()%int(max - min +1)+ min;//[min,max]int num =rand()%int(max - min)+ min;//[min,max)int num =rand()%int(max - min)+ min +1;//(min,max]return num;intrand_aroundX(int x,float y){#y是随机数在x附近的振荡范围,如取0.05,则随机数的范围是[0.95x,1.05x]srand(time(0));int num=rand()%int(x*y*2+1)+int(x*(1-y));return num;}