level 2
☞我是您爸
楼主
cpp文件是需要cin>>的,请问在写linux shell脚本的时候该怎么在./*.cpp之后,输入参数?
shell script如下:
//-----------------------
#!/bin/bash
for param1 in 2.5 3.0
do
./main
done
//--------------------------
cpp如下:
//----------------------------
#include <iostream>
#include <fstream>
using namespace std;
int main(){
double param1;
cin>>param1;
ofstream dd("data.txt",ios::out);
if(!dd) { cout<<"fail to open data.txt\n"; exit (0); }
dd<<param1;
dd.close();
return 0;
}
//-----------------------------
就是说,在shell script的./main之后应该跟什么命令,可以把定义的参数给main?
2020年06月17日 23点06分
1
shell script如下:
//-----------------------
#!/bin/bash
for param1 in 2.5 3.0
do
./main
done
//--------------------------
cpp如下:
//----------------------------
#include <iostream>
#include <fstream>
using namespace std;
int main(){
double param1;
cin>>param1;
ofstream dd("data.txt",ios::out);
if(!dd) { cout<<"fail to open data.txt\n"; exit (0); }
dd<<param1;
dd.close();
return 0;
}
//-----------------------------
就是说,在shell script的./main之后应该跟什么命令,可以把定义的参数给main?