【发布时间】:2013-10-31 17:28:15
【问题描述】:
我正在尝试编写一个简单的 Bash 脚本来编译我的 C++ 代码,在这种情况下,它是一个非常简单的程序,它只是将输入读入向量,然后打印向量的内容。
C++ 代码:
#include <string>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<string> v;
string s;
while (cin >> s)
v.push_back(s);
for (int i = 0; i != v.size(); ++i)
cout << v[i] << endl;
}
Bash 脚本运行.sh:
#! /bin/bash
g++ main.cpp > output.txt
这样就可以编译我的 C++ 代码并创建 a.out 和 output.txt(因为没有输入,所以它是空的)。我使用“input.txt
【问题讨论】:
-
好吧,至少它编译好了。这比这个网站上的大多数都好。
-
cat "input.txt" | ./a.out > output.txt
-
或
./a.out < "input.txt" > "output.txt"也可能会起作用。但是我用的是tcsh,所以ymmv。