zoukankan      html  css  js  c++  java
  • c++基础回顾

    #include <iostream>

    #include <vector>

    #include <string>

    int main(int argc, const char * argv[]) {

        // insert code here...

        std::cout << "Hello, World! ";

        int a=0;

        std::cout <<(a==0?"a==0":"a!=0");

        int b[10] = {10,3,3,3};

        std::vector<int> c;

        c.push_back(10);

        c.push_back(40);

        c.push_back(33);

        int d=c[0];

        int e=c[1];

        int f=c[2];

        std::cout<<d<<std::endl;

        std::cout<<e<<std::endl;

        std::cout<<f<<std::endl;

        std::cout<<c.size()<<std::endl;

        

        for (int i=0; i<c.size();i++) {

            std::cout<<c[i]<<std::endl;

        }

        

        char str[128]="Hello World";

        char *p="Hello World";

        

        std::string s;

        s="232sdsafdas912::";

        

        s+="dsadsad[[";

        

        

        return 0;

    }

    #include <iostream>

    int main(int argc, const char * argv[]) {

        int max(int x,int y);

        int a,b,c;

        std::cout<<"输入两个数字"<<std::endl;

        std::cin>>a>>b;

        c=max(a, b);

        std::cout<<c;

    }

    int max(int x,int y){

        int z;

        if(x>y) z=x;

        else z=y;

        return z;

    }

    #include <iostream>

    using namespace std;

    class Student{

    private:

        int num;

        int score;

    public:

        void setdata(){

            cin>>num;

            cin>>score;

        }

        void display(){

            cout<<"num="<<num<<endl;

            cout<<"score="<<score<<endl;

        }

    };

    Student s1,s2;

    int main(int argc, const char * argv[]) {

        s1.setdata();

        s1.display();

        s2.setdata();

        s2.display();

    }

    #include <iostream>

    using namespace std;

    class Complex{

    public:

        Complex(){real=0;imag=0;}

        Complex(double r,double i){real=r;imag=i;}

        Complex operator + (Complex &c2);

        void display();

    private:

        double real;

        double imag;

    };

    Complex Complex::operator+(Complex &c2){

        Complex c;

        c.real=real+c2.real;

        c.imag=imag+c2.imag;

        return c;

    }

    void Complex::display(){

        cout<<"("<<real<<","<<imag<<"i)"<<endl;

    }

    int main(int argc, const char * argv[]) {

        Complex c1(3,4),c2(5,-10),c3;

        c3=c1+c2;

        cout<<"c1=";

        c1.display();

        cout<<"c2=";

        c2.display();

        cout<<"c1+c2=";

        c3.display();

        return 0;

    }

    #include <iostream>

    #include <fstream>

    using namespace std;

    int main(int argc, const char * argv[]) {

        int a[10];

        ofstream outfile("f1.txt",ios::out);

        if(! outfile){

            cerr<<"open error!"<<endl;

            exit(1);

        }

        cout<<"enter 10 integer numbers:"<<endl;

        for (int i=0;i<10;i++) {

            cin>>a[i];

            outfile<<a[i]<<" ";

        }

        outfile.close();

        return 0;

    }

  • 相关阅读:
    手机兼容性测试
    Monkey测试
    ADB常用指令
    ADB移动端测试
    关于虚拟网卡V1,V8的问题
    1
    排序算法
    查找算法
    二叉树的计算
    队列
  • 原文地址:https://www.cnblogs.com/daochong/p/5215599.html
Copyright © 2011-2022 走看看