首页 > 解决方案 > 如何使用输入参数作为文件的传递?

问题描述

我是 C++ 的新手,我目前正在尝试解决的任务是将一个目录中 *.txt 文件中的一些数据解析为另一个目录中的 *+1.txt 文件。我使用了代码示例:

#include <iostream>
#include <fstream>  
#include <string>
#include <stdio.h>

int main(int argc, char*argv[]){
std::ifstream input("C:\\Tmp\\example.txt");
std::string outfilepass = "";
    outfilepass +=argv[2];
    outfilepass +="\\";
    outfilepass += argv[1];
std::ofstream outfile(outfilepass);
return 0;
}

如果我编译它然后使用 sample.exe example1.txt "C:\Tmp\NewFolder\" 在 Windows 10 中一切正常,但在 Windows 7 中没有任何反应。

!更新

我找到了一些有用的链接来帮助我找到解决方案。问题出在应用程序的目标平台上。(我用过 VS 2019)。以下是一些有用的链接:

Visual Studio 2015 将目标平台更改为 windows 7

https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?redirectedfrom=MSDN&view=vs-2019

标签: c++

解决方案


我找到了一些有用的链接来帮助我找到解决方案。问题出在应用程序的目标平台上。(我用过 VS 2019)。以下是一些有用的链接:

Visual Studio 2015 将目标平台更改为 windows 7

https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?redirectedfrom=MSDN&view=vs-2019

该解决方案是内置的

#define WINVER 0x0601 и _WIN32_WINNT 0x0601

推荐阅读