[TOC]
头文件
#include
1 2 3 4 5 6 7
| random_shuffle();
char s[4]; random_shuffle(s, s+4);
vector s; random_shuffle(s.begin(), s.end());
|
#include <string.h>
使用以下几种函数判断文件是否存在
#include <fstream>
–> 使用ifstream打开文件流,成功则存在,失败则不存在;
#include <stdio.h>
–> 以fopen读方式打开文件,成功则存在,否则不存在;
#include <unistd.h>
–> 使用access函数获取文件状态,成功则存在,否则不存在
#include <sys/stat.h>
–> 使用stat函数获取文件状态,成功则存在,否则不存在
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| #include <sys/stat.h> #include <unistd.h> #include <fstream> #include <string> #include <iostream>
using namespace std; bool isFileExists_ifstream(string& name) { ifstream f(name.c_str()); return f.good(); } bool isFileExists_fopen(string& name) { if (FILE *file = fopen(name.c_str(), "r")) { fclose(file); return true; } else { return false; } } bool isFileExists_access(string& name) { return (access(name.c_str(), F_OK ) != -1 ); }
bool isFileExists_stat(string& name) { struct stat buffer; return (stat(name.c_str(), &buffer) == 0); }
|
python c-api
https://docs.python.org/zh-cn/3.10/c-api/long.html