我正在尝试在c++
中为执行其他程序的QNX
编写程序。
为此,我有4个文件要处理。
file1
file2.l
file3.c
file4.bin
算法是
if file1 is not present then execute file2.l
Execute file3.c
Execute file4.bin
这是我尝试过的代码。
#include<fstream>
#include<iostrea>
using namespace std;
int main(){
ifstream ifile;
ifile.open("file1");
if(!ifile){
// system("Code to run file2.l program in termnal")
}
// system("Code to run file3.c program in termnal")
system("./file4.bin")
我需要知道如何使用file2.l
中的file3.c
执行c++
和QNX
System()仅用于执行系统功能,例如'cp'或'shutdown'。要启动程序,可以使用spawn()或spawnv()函数。
#include <iostream>
using namespace std;
inline bool fileCheck(const string &name)
{
if (FILE *file = fopen(name.c_str(), "r"))
{
fclose(file);
return true;
}
else
{
return false;
}
}
int main(void)
{
// Replace with your own code
if (fileCheck("time.exe"))
{
// exists...
system("swap.exe");
}
else
{
// doesn't exists...
system("swap.exe");
}
return 0;
}
程序首先创建一个内联函数来快速检查文件的存在,然后出现main()来完成所需的工作。