min()

min()は最小値を返します。

書式は次の通りです。


  template const T& min(const T& x, const T& y);
  template const T& min(const T& x, const T& y, pred pr);
  template T min(const valarray& x);
  static T numeric_limits::min() throw();
  T valarray::min() const;
  

次の例は、それぞれ2個の整数と文字列の最小値を出力するプログラムの例です。


    #include <iostream>
    #include <string>
    
    int main(void)
    {
      int v1 = 12, v2 = 30;
    
      std::cout << std::min(v1, v2) << std::endl;
    
      std::string s1 = "ABC", s2 = "xyz";
    
      std::string s3 = std::min(s1, s2);
    
      std::cout << s3 << std::endl;
    
      return 0;
    }
  

実行結果は次の通りです。


    12
    ABC
  

関連項目

max()


  


C++目次 inserted by FC2 system