zoukankan      html  css  js  c++  java
  • Ⅱ 边边角角①

    一、输入输出流

    1.cout默认的是六位数字,如果想要输出特定的格式的话,就要有小技巧

     

     fixed:write floating-point values in fixed-point notation

    数据序列查找

    #include <iostream>
    #include <sstream>
    #include <string>
    #include <map>
    
    using namespace std;
    
    int main()
    {
        string line;
        string studID, studName;
        map<string, string> m;
    
        while (getline(cin, line))   //把cin的内容放入line,直到遇到
    、EOF,包含空格
        {
            if (line == "exit")
                break;
            istringstream is(line);
            is >> studID >> studName;
            m.insert({studID, studName});   //插入,C++11
        }
    
        string key;
        cin >> key;
        auto p = m.find(key);   //key就像是一个标志,只要找到它,再输出他对应的即可
        if(p!= m.end())
            cout <<  p->second << endl;
        else
            cout << "not in the list." << endl ;
    }

    二、基本数据类型

    三、控制结构

    1.判断

    2.循环

    3.转移

    break:跳出一层循环{。。}

    continue:不跳出循环,往后一个

    四、构造数据类型

    1.枚举类型

     2.数组

     3.指针

    4.动态内存分配

    #include <iostream> 
    #include <cstdlib> 
    #include <algorithm> 
    using namespace std;
    
    int main() { 
        int n; 
        int *a = NULL; 
        cin >> n; 
        a = new int[n];    //分配
        for (int i=0; i<n; i++) 
            a[i] = rand()%100;
         for (int i=0; i<n; i++)
             cout << a[i] << "	";
         cout <<endl;
        sort(a, a+n);
        for (int i=0; i<n; i++) 
            cout << a[i] << "	"; 
        cout <<endl; 
        delete []a;   //释放
        return 0;
    }                    

     5.指针常量&常量指针

    ①能不能修改指针的地址

    ②能不能修改指针所指的数据

     ①②合体!~~

    6.引用类型 

     引用是变量的别名,那如果你定义的时候没有赋初值,就找不到自己的另一个名字了,所以引用必须初始化;如果是int &j就要跟变量在一起,如果是const int &j就可以跟数123在一起啦,也可以跟初始化了的变量(间接跟数一起),而且,有代价:不能修改!

     7.类型转换

  • 相关阅读:
    理解CSS中BFC
    js 异步执行顺序
    javascript中继承方式及优缺点(三)
    javascript中继承方式及优缺点(二)
    javascript中继承方式及优缺点(一)
    javascript中的原型和原型链(五)
    javascript中的原型和原型链(四)
    javascript中的原型和原型链(三)
    跨域问题及解决思路
    lambda表达式之方法引用
  • 原文地址:https://www.cnblogs.com/syzyaa/p/12672833.html
Copyright © 2011-2022 走看看