c++控制台 存储 外部程序给 main函数传进来的参数
#include <iostream> #include <fstream> #include <string> #include <vector> using namespace std; //文本文件 写文件 int main( int arge,char **argv) { cout << "写文件:" << endl << endl; ofstream ofs; //3.指定打开文件 ofs.open("test.txt", 0x02);//ios::out //4.写内容 ofs << "写文件:" << endl; char ** temp = argv; /* 保留argv */ vector<string> str; if (*temp != nullptr) { str.push_back(*(temp + 1)); str.push_back(*(temp + 2)); } ofs << str.at(0) << endl; ofs << str.at(1) << endl; //5.关闭文件 ofs.close(); system("pause"); return 0; }