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;
}
复制代码

 

posted @   雾枫  阅读(69)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
点击右上角即可分享
微信分享提示