C++(一)

一、Hello World


#include
using namespace std;
int main(){
    cout << "hello" <

编译

g++ helloworld.cpp -o helloworld

执行

./helloworld

二、字符串

  • 字符串拼接
  • 字符串打印
#include
#include
using namespace std;

int main(){

    string name = "fzj";
    string school = "zju";
    cout << name + "\n" + school << endl;
    return 0;

}

三、输入输出


#include
#include
using namespace std;

int main(){

    string s;
    cin >> s;
    cout << s <

四、集合

  • 创建集合
  • 打印集合

#include
#include
using namespace std;

int main(){

    vector v1;
    int word;
    while(cin >> word){
        v1.push_back(word);
    }

    for(vector::size_type ix = 0;ix != v1.size();++ix){
        cout << v1[ix] << endl;
    }

}

输入EOF,终止输入

五、函数

  • 函数调用
  • 函数重载

#include
#include
#include
using namespace std;

string getString(string str){
    return str;
}

string getString(string str,string str2){
    return str + str2;
}

int main(){

    string name = "fzj";
    cout << getString(name) << endl;
    cout << getString(name,"/nzju") << endl;
    return 0;

}

你可能感兴趣的:(C++(一))