本站電子書

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

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




u1401_1.cpp


#include <iostream>

int main() {
#if -1 > 0
   std::cout << "mm"
             << std::endl;
#elif 1 > 0
   std::cout << "ok"
             << std::endl;
#else
   std::cout << "xx"
             << std::endl;
#endif

   return 0;
}
 
/* Kaiching Chang 
   u1401_1.cpp
   2014-02 */

u1401_2.cpp


#include <iostream>
#define DEMO1 10

int main() {
#ifdef DEMO1
   std::cout << "demo1"
             << std::endl;
#else
   std::cout << "no demo1"
             << std::endl;
#endif

#ifndef DEMO2
   std::cout << "no demo2"
             << std::endl;
#else
   std::cout << "demo2"
             << std::endl;
#endif

   return 0;
}
 
/* Kaiching Chang 
   u1401_2.cpp
   2014-02 */

u1402_1.cpp


#include <iostream>
#define DEMO 10

int main() {
   std::cout << DEMO
             << std::endl;

#undef DEMO

   //std::cout << DEMO
   //          << std::endl;

   return 0;
}
 
/* Kaiching Chang 
   u1402_1.cpp
   2014-02 */

u1402_2.cpp


#include <iostream>
#define Prints(arg) std::cout << #arg 

int main() {
   Prints(hello);
   std::cout << std::endl;

   return 0;
}
 
/* Kaiching Chang 
   u1402_2.cpp
   2014-02 */

u1402_3.cpp


#include <iostream>
#define F(n, a) int f##n() {return a;}

F(test, 0);
F(function, 1);
F(rrr, 2);

int main() {
   std::cout << ftest()
             << std::endl;
   std::cout << ffunction()
             << std::endl;
   std::cout << frrr()
             << std::endl;

   return 0;
}
 
/* Kaiching Chang 
   u1402_3.cpp
   2014-02 */

u1403_1.cpp


#include <iostream>
#include <string>

int main() {
   std::string s = "There is no spoon.";
   std::cout << s.find("no")
             << std::endl;

   return 0;
}
 
/* Kaiching Chang 
   u1403_1.cpp
   2014-02 */

u1403_2.h


class Demo {
public:
   int a;
   int b;
   
   int do_something();
};
 
/* Kaiching Chang 
   u1403_2.h
   2014-02 */

u1403_2.cpp


#include <iostream>
#include "u1403_2.h"

int Demo::do_something() {
   return a + b;
}

int main() {
   Demo d;
   d.a = 1;
   d.b = 2;
   std::cout << d.do_something()
             << std::endl;

   return 0;
}
 
/* Kaiching Chang 
   u1403_2.cpp
   2014-02 */

the end

沒有留言: