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

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

How to parse command line parameters.

2019-11-10 17:58:04
字體:
供稿:網(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ā)表
主站蜘蛛池模板: 浏阳市| 油尖旺区| 稷山县| 香格里拉县| 台湾省| 蓝山县| 汝南县| 克什克腾旗| 四平市| 双峰县| 客服| 宜春市| 南澳县| 乐山市| 永登县| 阿瓦提县| 黄大仙区| 确山县| 仁寿县| 当涂县| 巴彦县| 泸西县| 海门市| 九龙城区| 广德县| 都江堰市| 淮安市| 民权县| 韩城市| 大兴区| 油尖旺区| 鄂伦春自治旗| 柞水县| 湘潭市| 盘锦市| 蓝田县| 绥滨县| 宜章县| 南木林县| 荣昌县| 山西省|