学习C++主函数的参数输入,用于从command line中读取参数,下面以读取视频文件为例进行说明
#include <iostream>
#include <fstream>
#include <string>
#include <opencv2/opencv.hpp>
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "usage: play_video <video_path>" << std::endl;
return -1;
}
std::string video_path = argv[1];
// check video file exist or not
std::ifstream image_file(video_path);
if (!image_file.is_open()) {
std::cerr << "Video file not exist!" << std::endl;
return -1;
}
// VideoCapture
cv::VideoCapture cap(video_path);
if (!cap.isOpened()) {
std::cerr << "Open Video Failed!" << std::endl;
return -1;
}
// Video Processing code here
// TODO
return 0;
}
标签:argc,读取,int,C++,函数参数,include
From: https://www.cnblogs.com/Todd-Qi/p/17141349.html