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

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

How to parse command line parameters.

2019-11-09 20:07:43
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
#include <iostream>using namespace std;// 控制臺(tái)傳的參數(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ā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 兰西县| 密云县| 天峨县| 花莲县| 和政县| 耿马| 孝感市| 炉霍县| 平罗县| 体育| 临城县| 黄石市| 云浮市| 黑水县| 闸北区| 高陵县| 白银市| 辽阳县| 滦平县| 石门县| 北宁市| 鹰潭市| 疏勒县| 黄浦区| 青田县| 个旧市| 桦南县| 兰考县| 肇庆市| 象州县| 丰城市| 古田县| 盐城市| 府谷县| 江孜县| 禹州市| 奎屯市| 济阳县| 邹平县| 宜阳县| 青州市|