// C5_8.cpp : Defines the entry point for the console application. // 利用 While 迴圈計算字元 #include "stdafx.h" #include using namespace std; int main(int argc, char* argv[]) { const int MAX = 100; char buffer[MAX]; int count = 0; cout << "請輸入小於 100 字元的字串: "; cin.getline(buffer, MAX, '\n'); while(buffer[count] != '\0') count++; cout << endl << "字串\""<< buffer << "\"有" << count << "個字元"; cout << endl; return 0; }