柏安 10 發表於 May 6, 2008 檢舉 Share 發表於 May 6, 2008 說明:先假設你宣告一個變數為 string a你可以指定a為某一字串例如:a="hello"如果要求字串的長度就用size函數例如:a.size()a.size()就會=5#include<iostream>#include<string>using namespace std;int main(){ int i=0,j=0; while(1){ string a; cout<<"請輸入字串(輸入quit離開):"; cin>>a; if(a=="quit")break; else{ j++; i=i+a.size(); cout<<"字串"<<a<<"長度為"<<a.size()<<"\n"; } } cout<<"輸入"<<j<<"個字串,總長度為"<<i<<"\n"; system("pause");} 鏈接文章 分享到其他網站
Recommended Posts