// C5_3.cpp : Defines the entry point for the console // application. // 字串處理 #include "stdafx.h" #include using namespace std; int main(int argc, char* argv[]) { const int Limit = 100; // 設定陣列最大元素數 char string[Limit]; // 宣告變數 int Counter = 0; // 字元計數器 cout << "請輸入一字串小於 100 字元 : "; cin.getline(string, Limit, '\n'); // 讀取一字串直到 \n while(string[Counter]!= '\0') // 設定計數器 Counter++; cout << endl << "字串 \"" << string //利用脫逸字元 << "\" 有 " << Counter << " 字元."; cout << endl; return 0; }