// C5_7.cpp : Defines the entry point for the console application. // 字串計數--利用指標 #include "stdafx.h" #include using namespace std; int main(int argc, char* argv[]) { const int Mlimit = 100; // 陣列最大元素值宣告(常數) char inputBuf[Mlimit]; // 建立輸入緩衝器 char* Pointer=inputBuf; // 指標於陣列 cout << endl // 輸入提訊息 << "中J一字串小於 " << Mlimit << " 字元 : " ; cin.getline(inputBuf, Mlimit, '\n'); //讀取一字串直至 \n while(*Pointer) // while 迴圈直到 \0 { cout << Pointer << endl; Pointer++; } cout << endl << "字串 \"" << inputBuf << "\" 有 " << Pointer-inputBuf << " 字元。"; cout << endl; return 0; }