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 对象的引用

原文地址:https://www.cnblogs.com/yican/p/3899957.html