如何使用POSIX在C ++中执行命令并获取命令输出?
在这里,我们将看到如何通过C++使用POSIX命令。该过程非常简单,我们必须使用名为的函数system()。在其中,我们必须传递字符串。该字符串将包含POSIX命令。
语法如下。
system(“command”)
示例
#include <iostream>
using namespace std;
int main () {
cout << "Print string using echo command" << endl;
system("echo 'Hello World'");
cout << "Calculate math expression using bc" << endl;
system("echo '22 / 7' | bc -l");
return 0;
}输出结果
Print string using echo command Hello World Calculate math expression using bc 3.14285714285714285714
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短