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.类型转换

  • 相关阅读:
    使用CustomValidate自定义验证控件
    C#中金额的大小写转换
    Andriod出错之Unable to build: the file dx.jar was not loaded from the SDK folder!
    VC 编写的打字练习
    机房工作笔记Ping只有单向通
    web服务协同学习笔记(1)
    Dll 学习3 将MDI子窗口封装在DLL中
    机房工作学习文件共享
    Andriod出错之Failed to find an AVD compatible with target 'Android 2.2'
    Andriod出错之wrapper was not properly loaded first
  • 原文地址:https://www.cnblogs.com/syzyaa/p/12672833.html
Copyright © 2011-2022 走看看