如何使用输入参数作为文件的传递?

How can I use input parameter as a pass to the file?

本文关键字:文件 何使用 输入 参数      更新时间:2023-10-16

我是 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;
}

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

!更新

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

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

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

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

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

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

该解决方案是在发布版本中构建的

#define WINVER 0x0601 и _WIN32_WINNT 0x0601