本站電子書

您可以在這些電子書店找到本站電子書: Google Play 圖書iBooks StoreHyReadReadmooPubu
===>>>本站推出學習遊戲意見調查<<<===《如何自學程式設計》入選 Google Play 台灣地區2016年度最佳書籍

C++ 速查手冊 V1.00 - 單元 12 範例




u1201.cpp


#include <iostream>
 
int main() {
   char a = 'a';
   short b = 5;
   int c = 156;
   long d = 5;
   float e = 9.8;
   double f = 12.5;
    
   if (b) {
      std::cout << "short => bool, " 
                << typeid(b).name() 
                << std::endl;
   }
   std::cout << "char => int, " 
             << (a / b) 
             << ", " 
             << typeid(a / b).name() 
             << std::endl;
   std::cout << "short => long, " 
             << (b * d) 
             << ", " 
             << typeid(b * d).name() 
             << std::endl;
   std::cout << "int => float, " 
             << (c / e) 
             << ", " 
             << typeid(c / e).name() 
             << std::endl;
   std::cout << "double => int, " 
             << (c = f)  
             << ", " 
             << typeid(c).name() 
             << std::endl;

   return 0;
}

/* Kaiching Chang
   u1201.cpp
   2014-02 */

u1202.cpp


#include <iostream>
 
int main() {
   char a = 'a';
   int b = 97;

   std::cout << a
             << std::endl;
   std::cout << b
             << std::endl; 
   std::cout << static_cast<char>(b)
             << std::endl;
   std::cout << static_cast<int>(a)
             << std::endl;

   return 0;
}

/* Kaiching Chang
   u1202.cpp
   2014-02 */

the end

沒有留言: