make_pair() andp air and function fflush()

function name: fflush(FILE *stream)
function: clear the read and write buffer, you need to immediately write the output buffer data into the specified stream;
head file: stdio.h
prototype: int fflush(FILE *stream)
the "stream" is the stream to be washed編程

make_pair() andp air
std::pair the main purpose is to combine two data into a single data, the two data can be the same type of different types, such as std::pair<int, float> or std::pair<double, double>, and so on. A pair is essentially a structure whose main two member variables are first and second, and these two variables can be used directly. initialize a pair you can use the constructor, or you can use the std::make_pair function. the make_pair function is defined as follows:
template pair make_pair(T1 a, T2 b) {return pair(a ,b);}
general make_pair are used in the position where need to pair to be the parameters, you can directly call make_pair generated pair object, another usage is that the pair can accept implicit conversions which gives greater flexibility, but this will be the following questions: For example, the following two definitions:
std::pair<int>(1,1.1);函數

std::make_pair(1, 1.1);
where the first second variable is a float type, and the make_pair function converts the second variable to a double type, this problem in programing is the need to draw attentionflex

std::pair主要的做用是將兩個數據組合成一個數據,兩個數據能夠是同一類型或者不一樣類型。例如std::pair<int,float> 或者 std::pair<double,double>等。pair實質上是一個結構體,其主要的兩個成員變量是first和second,這兩個變量能夠直接使用。初始化一個pair能夠使用構造函數,也能夠使用std::make_pair函數,make_pair函數的定義以下:
template pair make_pair(T1 a, T2 b) { return pair(a, b); }
通常make_pair都使用在須要pair作參數的位置,能夠直接調用make_pair生成pair對象。 另外一個使用的方面就是pair能夠接受隱式的類型轉換,這樣能夠得到更高的靈活度。可是這樣會出現以下問題:例若有以下兩個定義:
std::pair<int, float>(1, 1.1);this

std::make_pair(1, 1.1);
其中第一個的second變量是float類型,而make_pair函數會將second變量都轉換成double類型。這個問題在編程是須要引發注意。下面是一段pair與make_pair的例子程序:prototype

相關文章
相關標籤/搜索