C++ 入門指南 V2.00 - 單元 1 範例及練習程式碼



demo.cpp


// 引入標準程式庫中相關的輸入、輸出程式
#include <iostream>
// 引入標準程式庫中相關的字串程式
#include <string>

// std 為標準程式庫的命名空間 
using namespace std;
 
int main(void) {
   // 下面建立名稱為 m , string 型態的物件
   // 小括弧為 string 的建構子
   // 雙引號為字串字面常數
   string m("There is no spoon.");

   // cout 用來輸出的物件
   // endl 為新行符號 '\n'     
   cout << endl;
   cout << m << endl;    
   cout << endl << endl;
    
   return 0;
}
 
/* 檔名: demo.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

demo2.cpp


#include <iostream>
#include <string>

using namespace std;
 
int main(void) {
   string m("There is no spoon.");

   cout << endl;
   cout << m << endl;    
   cout << endl << endl;
    
   return 0;
}
 
/* 檔名: demo2.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

demo3.cpp


#include <iostream>
#include <string>

int main(void) {
   string m("There is no spoon.");

   cout << endl;
   cout << m << endl;    
   cout << endl << endl;
    
   return 0;
}
 
/* 檔名: demo3.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

demo4.cpp


#include <iostream>
#include <string>

int main(void) {
   std::string m("There is no spoon.");

   std::cout << std::endl;
   std::cout << m << std::endl;    
   std::cout << std::endl << std::endl;
    
   return 0;
}
 
/* 檔名: demo4.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

demo5.cpp


#include <iostream>
#include <string>

int main(void) {
   std::string m("There is no spoon.");

   std::cout << std::endl << m << std::endl << std::endl << std::endl;
    
   return 0;
}
 
/* 檔名: demo5.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

the end

沒有留言: