算法学习 —— 使用Linux C++练习OJ

一、简单输出

简单的小程序

1、安装g++

sudo install g++

2、编写c++程序,helloworld.cpp

#include<iostream>
using namespace std;
int main(){
        cout<<"hello"<<endl;
        return 0;
}

3、编译


g++ helloworld.cpp -o hello

会生成一个hello程序

4、执行

./hello

简单的输入输出

int a,b;
cin >> a >> b;
string name
cin >> name;

getline获取整行文本

二、数组

1、显示初始化数组

    int[3] array = {1,2,3};

三、宏函数


#include<iostream>
using namespace std;

#define FFI(a,b) for(int i=1;i<b;i++)
#define M 8

int main(){

	FFI(1,10) cout << i << endl;

	return EXIT_SUCCESS;

}


原文地址:https://www.cnblogs.com/fonxian/p/5522069.html