cpp文件有cin>>时,如何写shell script?
linux吧
全部回复
仅看楼主
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
level 14
既然用脚本就别交互了,老老实实用argv[]之类的吧[阴险]
2020年06月18日 00点06分 2
好的[惊讶]
2020年06月18日 02点06分
level 1
加油
2021年04月29日 05点04分 3
level 13
command < file
# or
command <<< string
2021年05月02日 14点05分 5
谢谢!帮大忙了[玫瑰]
2021年11月11日 09点11分
string和cin对接,请问file可以和什么对接呢?
2021年11月11日 09点11分
1