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
関連記事
大括弧を表示するには、\left[ または \right] を使う。 例 $\left[ \left( \frac{x}{y} \right) \right]$ 結果 片方だけの大括弧 片方だけのカッ …
matplotlib で x, y軸・タイトルのフォントサイズを調整する
ラベルの fontsize で指定する。 例 import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2, 100) …
2023/01/18
matplotlib のグラフ作成と gnuplot との対応 比較
2022/10/14
pythonで配列(リスト)の、ある要素がわかっているときにその次の要素を取得する方法。