.open files using argc and argv in C++

时间:2021-08-04 01:19:04

I have some code Which is supposed to open two .dat file at the same time and eventually load the files over to a method to deal with them. I am not sure how to load the two files in using the code I have been given. I will show below.

我有一些代码,它应该同时打开两个.dat文件,并最终将文件加载到一个方法来处理它们。我不知道如何使用我给出的代码加载这两个文件。我将在下面展示。

This is my main

这是我的主要

int main(int argc, char** argv)
{
// Start main class with command-line args



GPXport run(argc, argv);
return 0; 
}

This is the code part to load in the files.

这是加载文件的代码部分。

ofstream output;

// Open files
file_one.open(argv[1]);
file_two.open(argv[2]);
output.open(argv[3]);

if (! file_one) {
    cout << "Error reading: " << argv[1] << endl;
} else if (! file_two) {
    cout << "Error reading: " << argv[2] << endl;
} else if (! output) {
    cout << "Error creating: " << argv[2] << endl;
} else {
    cout << "Master: " << argv[1] << endl <<
            "Slave: " << argv[2] << endl <<
            "Output file: " << argv[3] << endl;
}

Now the problem is, I do not understand the argv and argc situation. How do i get the two file locations to this code?

现在的问题是,我不了解argv和argc的情况。如何获取此代码的两个文件位置?

Thanks

谢谢

Edit---

编辑 - -

I also have this before the second part of the code..

在代码的第二部分之前我也有这个...

 GPXport::GPXport(int argc, char **argv)  
 {
using namespace std;
if (argc != 4) {
    cout << "Usage: ./gpsfix_cpp <master> <slave> <output>" << endl;
    exit(1);
  }

1 个解决方案

#1


1  

Run compiled executable from command line as:

从命令行运行已编译的可执行文件:

[your executable] [input path1] [input path2] [output path]

if any path contains spaces quote the path.

如果任何路径包含空格引用路径。

#1


1  

Run compiled executable from command line as:

从命令行运行已编译的可执行文件:

[your executable] [input path1] [input path2] [output path]

if any path contains spaces quote the path.

如果任何路径包含空格引用路径。