Linux下自动编译和运行c++文件的脚本

运行环境

操作系统:ubuntu 16.04
编程语言: C++
编译链接工具:g++

实现目标

  • cpp文件自动编译并且生成同名的.out文件。
  • 自动运行.out文件查看输出。

脚本程序

  1. 将以下脚本程序命名为autorun.sh
#!/bin/bash

cppname=$1
outname=${cppname%.*}
outname=$outname".out"
g++ $cppname -o $outname
./$outname
  1. 运行sudo chmod +x autorun.sh使文件可执行。

使用示例

autorun放在cpp文件所在目录下,在shell中输入如下命令,请将cpp文件名字替换成自己的cpp文件名。

./autorun.sh decimalPointAlighment.cpp 

猜你喜欢

转载自blog.csdn.net/yucicheung/article/details/80053988
今日推荐