我是 C++ 的新手(今天开始,只用了大约 10 分钟)。如何在终端上编译和运行?这是一个计算可用座位数 (r*s) 的基本程序。第一行是行数和座位数,第二行是票数(参加人数)。然后输出将分别显示有多少人坐着然后站着。
#include <stdio.h>
int main() {
int r, s, sit,stand,tickets;
freopen("sitin.txt", "r", stdin);
freopen("sitout.txt", "w", stdout);
scanf("%d %d", &r, &s);
scanf("%d", &tickets);
printf("%d %d\n",r*s,tickets-(r*s));
return 0;
}
最佳答案
与 gcc 编译器/链接器一起使用:
gcc -g -c myfile.c -o myfile.o -I.
编译myfile.c
生成目标文件 myfile.o
然后使用:
gcc -g myfile.o -o myfile
链接文件myfile.o
生成可执行文件 myfile
然后使用
执行它cat sitin.txt | ./myfile > sitout.txt
上面一行的作用是:1) 调用 cat
实用程序,将其传递给 sitin.txt
文件作为参数。 2) 重定向 stdout
的 cat
至 stdin
我的文件。 3) stdout
myfile 的重定向到 sitout.txt
文件
不要更改 stdin
的初始文件指针和标准输出 if going to use
猫 and
重定向`如您的问题所示。
关于c - 如何使用 "cat > "将信息写入终端中的 sitin.txt 然后它会输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35148905/