#include <stdio.h> //功能就是从命令行中传递字符串,并且打印出来
#include <iostream>
#include <fstream>
#include<iostream>
#include<string>
using namespace std;
int main(int argc, char* argv[])
{
char** p = argv;
if (argc > 1)
{
ifstream fid;
fid.open(*(++p), ios::in);
if (!fid)
cout << "文件打开失败" << endl;
string line;
getline(fid, line);
cout << line << endl;
argc--;
}
while (argc > 1)
{
puts(*(++p)); //打印 从命令行中 输入的字符串
argc--;
}
return 0;
}
//输入testc beijing shanghai
//输出 beijing
// shanghai
//C:\Users\S9029384\source\repos\agav_test\x64\Debug\mydata.txt
//argv[] 的第二个成员 应该输入要打开文件的目录字符串(命令行中输入的第一个字符串,本质是argv的第二个字符串),
/*
mydata.txt文件内容:
jiayougwp
*/
main函数的参数解析运用
最新推荐文章于 2023-03-31 16:48:07 发布