国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 桂平市| 彩票| 长阳| 礼泉县| 合水县| 咸丰县| 剑川县| 龙州县| 新密市| 泽库县| 长泰县| 康保县| 建湖县| 易门县| 美姑县| 博野县| 永丰县| 平利县| 琼结县| 开江县| 微山县| 界首市| 会宁县| 宿州市| 东阿县| 六枝特区| 南丹县| 客服| 太和县| 苏尼特右旗| 曲沃县| 家居| 沈丘县| 罗源县| 临夏市| 溧阳市| 元朗区| 桃园县| 涿鹿县| 临泽县| 潮安县|