- 获取参数getopt(), 头文件<unistd.h>
getopt(argc, argv, "g:r");
...
sscanf(optarg, "%s", counter);
- char[]复制拼接拼接
strcpy(file_path, path1);
strcat(file_path, path2);
- 配置读取config.txt
FILE *pfile;
pfile = fopen("./config.txt", "r");
fscanf(pfile, "%s", config->para1);
fscanf(pfile, "%s", config->para2);
fclose(pfile);
- 获取文件大小
pfile = fopen("./config.txt", "r");
fseek(pfile, 0L, SEEK_END);
length = ftell(pfile);
fseek(pfile, 0L, SEEK_SET);
- byte/char bit翻转
input = ((input&0xaa)>>1)|((input&0x55)<<1);
input = ((input&0xcc)>>2)|((input&0x33)<<2);
input = ((input&0xf0)>>4)|((input&0x0f)<<4);
- 程序计时 clock_t
time_start = clock();
process();
duration= clock()-time_start;
ms = diff*1000/CLOCKS_PER_SEC;
- 加载csv
#include <fstream>
#include <dirent.h>
#include <cstring>
#include <sstream>
using namespace std;
unsigned int load_csv(char* path, vector<vector<unsigned int>>& data){
vector<unsigned int> row;
string line, val;
ifstream fileIn(path, ios::in);
if (fileIn.is_open()){
while (getline(fileIn, line))
{
row.clear();
stringstream str(line);
while (getline(str, val, ','))
{
row.push_back(stoul(val));
}
data.push_back(row);
}
}
else{
perror("open csv");
return FILE_NOT_FOUND;
}
}