zoukankan      html  css  js  c++  java
  • 学习笔记(C++)

    1.stringstream等对象在标准库sstream中,非stringstream中

    2.字符串与整数转变

    字符串转整数

    string sinta("1234");

    const char *tchar;

    tchar=sinta.c_str();

    int inta;

    inta=atoi(tchar);

    整数转字符串

    int inta=12345;

    stringstream tsinta;

    tsinta << inta;

    string sinta =tsinta.str();//或者 string sinta; tsinta >> sinta;

    3.循环内定义的变量循环外是不可用的

     bool a=true;
     while(a){
      int i=1;
      a=false;
     }
     cout << i;//未定义
     for(int i=1;i<2;i++){}
     cout<< i;//未定义

     //CDT中隐藏控制台

    -mwindows 编译参数加表示无控制台

    -mconsole 表示控制台程序

    默认不加,两个都有...

    类的定义与使用

    class test{

    public:

    int abc;

    void t1(){};

    static void t2(){};

    //内部定义

    void t3(){

     cout << this.abc<<endl;

    }

    private:

    }

    //外部定义

    test::t1(){}

    test::t2(){}

    //使用

    //默认声明方式

    test t;

    t.t1();

    t::t2();

    t.t2();

    //new 方式,用完后可以用delete

    test * pt;

    pt= new test();

    delete pt;

    //标准IO

    strstream a;

    string b("dddd");

    a << b;

    string c;

    c <<a;

    //类的声明与定义,所有的定义成员定义之前必须声明..

    class a{
    public :
        int c;
        a(const a & b){//复制控制

        }
        a():c(10){};
    };
    class b{
    public :
        b(const b & b);
        b();
    };
    b::b(){}
    b::b(const b & b){}
    class c{
    public :
        c(const c & b){

        }
        c();
    };
    c::c(){}
     

     //操作符重载

    class b{
     public:
     //成员函数方法实现
     //自己通过this获得
     b& operator+(b& b){//b+b
      return b;
     }
     b& operator<<(int b){//b<<1
      return *this;
     }
    };
    class a{
     public:
     a& operator+(a& b){
      return b;
     }
    };
    //非成员普通函数方法实现
    //自己通过形参传入
    b& operator-(b & in ,b& s) //b-b
    {
     return in;
    }
    std::istream& operator<<(std::istream & in ,b& s) //cout <<b
    {
     return in;
    }
    a& operator<<(a& in ,b& s)//a <<b
    {
     return in;
    }
  • 相关阅读:
    C# dynamic class inherit from dynamicobject
    C# while timespan via Datetime and Stopwatch
    neo4j实现疾病知识图谱实战
    omop cdm数据质控
    mimic-omop专病数据生产ETL
    Oracle表空间与数据文件
    Oracle 11g 静默安装过程(Centos7)
    Hbase插件之Phoenix
    contentEditable
    jsx render
  • 原文地址:https://www.cnblogs.com/liushannet/p/2047043.html
Copyright © 2011-2022 走看看