ubuntu中运行C++函数定义示例
1 右击新建一个1.cpp文件
2 在文件中编写程序
#include <iostream>
#include <stdio.h>
void f(int a)
{
while (a--){
static int n = 0;
int x = 0;
std::cout << "n==" << n++ <<", x== " << x++ << '\n' ;
}
}
int main ()
{
f(3);
}
3 ctrl+alt+t新打开一个终端输入
g++ 1.cpp -o tests
./tests
4 运行成功显示
=0, x== 0
n==1, x== 0
n==2, x== 0