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
関連記事
python3 で文字列のリストを結合して1つの文字列にする方法
リストに対して、join メソッドを実行する。 例 list1 = [‘hello, ‘,’good ‘, ‘morning’] str1 = ”.join(list1) print(str1) 結 …
caption パッケージを使っておき、\caption* を使うと、図の番号を表示しないようにできる。 例 \usepackage{caption} \begin{document} \begin{ …
2023/01/18
matplotlib のグラフ作成と gnuplot との対応 比較
2022/10/14
pythonで配列(リスト)の、ある要素がわかっているときにその次の要素を取得する方法。