C 實用記錄

2022-08-04 23:51:13 字數 1771 閱讀 4861

一、工作中有時會用到的一些功能,記錄下來

//遍歷資料夾下的檔案,輸入:資料夾路徑,返回檔名的vector

void get_image_names(const

string &file_path, vector&file_names)

else

} while (_findnext(hfile, &fileinfo) == 0

); _findclose(hfile);

}}//呼叫方式

另一種比較方便的方法是,利用opencv中的glob

string filepath = ""

;vector

filenames;

glob(filepath, filenames,

true

);for

(auto c : filenames)

//不過資料型別為cv::string

所以要不是opencv直接用一般需要轉型別,比如char*或者string型別

uses_conversion;

cv::string b =filename;

string c =b;

const

char *p =c.data();

//

根據指定pattern對字串進行切分,類似python中的split

vector split(const

string &str, const

string &pattern)

return

res;

}//呼叫舉例

vectorres;

res = split(txtfile, "\\");

//

解決讀取中文編碼亂碼的情況

string utf8togb(const

char*str)

//

將檔案複製到指定資料夾

void copy_file(int flag,string s,string

name)

string target_path_name = target_path +name;

lpcstr target_path_name1 =target_path_name.c_str();

//cout << target_path_name1 << endl;

copyfile(source_path1, target_path_name1, true);//

false代表覆蓋,true不覆蓋

}

else

string target_path_name1 = target_path1 +name;

lpcstr target_path_name2 =target_path_name1.c_str();

//cout << target_path_name1 << endl;

copyfile(source_path1, target_path_name2, true);//

false代表覆蓋,true不覆蓋

}}

實用sql記錄

1.mysql建表語句 create table user id bigint 20 not null auto increment comment 主鍵 username varchar 50 not null comment 使用者名稱 password varchar 50 not null ...

vi vim實用操作記錄

1.視窗相關操作 vi o file1 file2 以橫屏分隔視窗開啟file1,file2,vi o file1 file2 以豎屏分隔視窗開啟file1,file2,ctrl w s橫屏分隔乙個視窗中開啟當前檔案 window split ctrl w v豎屏分隔乙個視窗中開啟當前檔案 wind...

實用Pandas操作記錄

from lxml import etree 檔案路徑 f e web crawler https免費http ip 第1頁https.html 生成html頁面的字串 html table text etree.tostring etree.parse f,etree.htmlparser dec...