国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

How to parse command line parameters.

2019-11-09 19:53:51
字體:
來源:轉載
供稿:網友
#include <iostream>using namespace std;// 控制臺傳的參數: "./a.out -f /home/in.txt -o /home/out.txt"int main(int argc, char* argv[]) { // argv[0]="./a.out"; // argv[1]="-f"; // argv[2]="/home/in.txt"; // argv[3]="-o"; // argv[4]="/home/out.txt"; // argc=5; if (argc < 5) { // Check the value of argc. If not enough parameters have been passed, inform user and exit. std::cout << "Usage is -in <infile> -out <outdir>/n"; // Inform the user of how to use the PRogram std::cin.get(); return 0; } else { // if we got enough parameters... char* myFile,* myPath, *myOutPath; std::cout << argv[0]<<endl; for (int i = 1; i < argc; i++,i++) { /* We will iterate over argv[] to get the parameters stored inside. * Note that we're starting on 1 because we don't need to know the * path of the program, which is stored in argv[0] */ cout<<argv[i]<<" "; if (string(argv[i]) == "-f") { // We know the next argument *should* be the filename: myFile = argv[i + 1]; } else if (string(argv[i]) == "-p") { myPath = argv[i + 1]; } else if (string(argv[i]) == "-o") { myOutPath = argv[i + 1]; } else { std::cout << "Not enough or invalid arguments, please try again./n"; return 0; } std::cout << argv[i+1] <<endl; } std::cin.get(); return 0; }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 铜陵市| 嘉鱼县| 台州市| 丹寨县| 淮南市| 伊川县| 余姚市| 山西省| 石阡县| 沙洋县| 罗甸县| 桂林市| 泸溪县| 崇信县| 伊宁县| 洮南市| 喀喇沁旗| 溧阳市| 广河县| 杨浦区| 尼木县| 锡林浩特市| 盐城市| 临武县| 六枝特区| 尖扎县| 乐至县| 邮箱| 博湖县| 灵武市| 元氏县| 水城县| 莒南县| 临颍县| 阿拉善右旗| 北票市| 从化市| 灵宝市| 海门市| 循化| 叶城县|