zoukankan      html  css  js  c++  java
  • c++标准库类型

    1.作用域操作符

    例如,需要从标准输入读取数据时,就用 std::cin。这些名字都用了:: 操作符,该操作符是作用域操作符,它的含义是右操作数的名字可以在左操作数的作用域中找到。因此,std::cin 的意思是说所需要名字 cin 是在命名空间 std 中定义的。

    2:命名空间

    #include <string>    
    #include <iostream>  
    // using declarations states our intent to use these names from the namespace std    
    using std::cin;   
    using std::string;
    int main()    
    {       
        string s;   
        // ok: string is now a synonym for std::string     
        cin >> s;    
        // ok: cin is now a synonym for std::cin   
        cout << s;    
        // error: no using declaration; we must use full name    
        std::cout << s; 
        // ok: explicitly use cout from namepsace std    
    } 

    3:cin读取string的流程

    1  读取并忽略开头所有的空白字符(如空格,换行符,制表符)。

    2  读取字符直至再次遇到空白字符,读取终止。 

    getiline(cin,string)不会忽略这些空白字符,会忠实读取

    4:string和vector的特有类型

    string::size_type  size_type是在string中定义的unsigned数据类型

    vector::size_type 这两个是储存下标的数据类型

    vetor::iterator vector = v.begin()的迭代器,进行可以读取和赋值

    vector::const_iterator 只可以读取

    迭代器的减法操作返回的是difference_type而不是新的迭代器

    当我们对普通 iterator 类型解引用时,得到对某个元素的非 const。而如果我们对 const_iterator 类型解引用时,则可以得到一个指向 const 对象的引用

  • 相关阅读:
    《构建之法》第8、9、10章的读后感和第一个sprint总结
    实验三 进程调度模拟程序
    构建之法第6、7章的读后感
    实验二 作业调度模拟程序
    0415博客园评价
    0414复利计算6.0-----结对编程
    0408~送给小伙伴的汉堡包
    学习进度条
    Sprint three
    sprint one
  • 原文地址:https://www.cnblogs.com/yican/p/3899957.html
Copyright © 2011-2022 走看看