length() で取得する。
例
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str1 = "Good morning";
cout << str1.length() << endl;
return 0;
}
結果
12
参考
上記のコードでは、バイト数を取得している。 全角文字列の場合には、注意が必要。
雑記
投稿日:
length() で取得する。
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str1 = "Good morning";
cout << str1.length() << endl;
return 0;
}
12
上記のコードでは、バイト数を取得している。 全角文字列の場合には、注意が必要。
執筆者:seyanen
関連記事
テキストを \flushright で囲めば良い。 例 \begin{flushright} Lorem, ipsum dolor sit amet consectetur adipisicing e …
2023/01/18
matplotlib のグラフ作成と gnuplot との対応 比較
2022/10/14
pythonで配列(リスト)の、ある要素がわかっているときにその次の要素を取得する方法。