gctl_toolkits/archive/addnoise/head.h

68 lines
1.3 KiB
C
Raw Normal View History

2024-09-10 20:25:18 +08:00
#ifndef _HEAD_H
#define _HEAD_H
#include "ctype.h"
#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "iostream"
#include "fstream"
#include "sstream"
#include "iomanip"
#include "vector"
#include "ctime"
#include "cmath"
#include "random"
#include "string.h"
#define BOLDRED "\033[1m\033[31m"
#define RESET "\033[0m"
using namespace std;
typedef vector<double> _1dArray;
typedef vector<int> _1iArray;
int open_infile(ifstream &infile,char* filename)
{
infile.open(filename);
if (!infile)
{
cout << BOLDRED << "error ==> " << RESET << "file not found: " << filename << endl;
return -1;
}
return 0;
}
int open_outfile(ofstream &outfile,char* filename)
{
outfile.open(filename);
if (!outfile)
{
cout << BOLDRED << "error ==> " << RESET << "fail to create the file: " << filename << endl;
return -1;
}
return 0;
}
string& replace_all(string& str,const string& old_value,const string& new_value,int &num) //替换str中所有lod_value为new_value,返回被替换的lod_value的个数
{
int count = 0;
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);
count++;
}
else break;
}
num = count;
return str;
}
struct node
{
_1dArray val;
};
typedef vector<node> nodeArray;
#endif