「C++」size()で文字列の長さを取得する方法

説明
size()で文字列の長さを取得します。
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
int main() {
string cftA = "abcdInfo";
string cftB = "";
 char cftC = cftA[2];
cout << "cftA.size()= " << cftA.size() << endl;
cout << "cftB.size()= " << cftB.size() << endl;
cout << "cftC = " << cftC << endl;
return 0;
}
int main() { string cftA = "abcdInfo"; string cftB = "";  char cftC = cftA[2]; cout << "cftA.size()= " << cftA.size() << endl; cout << "cftB.size()= " << cftB.size() << endl; cout << "cftC = " << cftC << endl; return 0; }
int main() {

  string cftA = "abcdInfo";
  string cftB = "";
 char cftC = cftA[2];
  cout << "cftA.size()= " << cftA.size() << endl;
  cout << "cftB.size()= " << cftB.size() << endl;
  cout << "cftC = " << cftC << endl;

 return 0;
}

実行結果
cftA.size()= 8
cftB.size()= 0
cftC = c

C++

Posted by arkgame