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

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

How to parse command line parameters.

2019-11-09 19:31:41
字體:
供稿:網(wǎng)友
#include <iostream>using namespace std;// 控制臺傳的參數(shù): "./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; }}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 隆德县| 赤城县| 香格里拉县| 司法| 新龙县| 柞水县| 新河县| 双峰县| 澄迈县| 紫金县| 灯塔市| 墨脱县| 平山县| 蒙阴县| 永登县| 孝昌县| 大冶市| 成武县| 玉田县| 拉孜县| 承德县| 张家界市| 长泰县| 柘荣县| 崇文区| 涿州市| 蒙城县| 西乡县| 渭南市| 洛川县| 留坝县| 嘉禾县| 永新县| 太谷县| 甘泉县| 蚌埠市| 德格县| 巴南区| 英吉沙县| 平潭县| 古丈县|