C++實現的一些功能代碼
阿新 • • 發佈:2019-01-26
code 輸出結果 tro put 代碼 ima () http 當前
將當前時間輸出到txt中:
調用c++中的fstream流文件,用tm結構獲取日期和時間,其在time.h中定義
#include <iostream> #include <time.h> #include <fstream> using namespace std; void writeTimeToTxt(string txtname) { ofstream fid(txtname); time_t tt = time(NULL); struct tm local_time; localtime_s(&local_time, &tt); fid<< "***testing date: " << local_time.tm_year + 1900 << "-" << local_time.tm_mon + 1 << "-" << local_time.tm_mday << " " << local_time.tm_hour << ":" << local_time.tm_min << ":" << local_time.tm_sec << endl; fid.close();return; } int main() { string txtname = "time.txt"; writeTimeToTxt(txtname); return 1; }
輸出的結果:
通過argv向程序中輸入參數:
#include <iostream> #include <string> using namespace std; int main(int argc, char* argv[]) { if (4 != argc) { cout << "input params error" << endl; return -1; } string type = argv[1]; string cutmethod = argv[2]; string resolution = argv[3]; cout << type << "_" << cutmethod << "_" << resolution << endl; system("pause"); return 1; }
輸出結果:
在vs中參數的輸入,項目-屬性-調試-命令參數-train expand 64x64 輸入的字符串,雙引號可加可不加
生成的exe調用過程中,.\OutputTimeToTxt.exe "train" expand 64x64 字符串的雙引號,可加可不加
C++實現的一些功能代碼