未分類

c++ で文字列を合成(連結)する方法

投稿日:

c言語では、sprintf 関数を使って文字列を合成(連結)することができる。

いっぽう、c++ では、文字列を string で表して「+」演算子で文字列を合成することができる。

#include <iostream>
#include <string>

using namespace std;
int main ()
{
string str1 = "Good ";
string str2 = "morning";

string gousei = str1 + str2;

cout << gousei << endl;

return 0;
}

結果

Good morning

-未分類

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

tex で文章を右寄せにする方法

テキストを \flushright で囲めば良い。 例 \begin{flushright} Lorem, ipsum dolor sit amet consectetur adipisicing e …

no image

tex でオーム記号を入力する方法

siunit のパッケージを使って、\si{\ohm} で入力する。 例 \usepackage{siunitx} \begin{document} \si{\ohm} \end{document} …

no image

matplotlib で縦横の罫線を出力する

罫線を出力するには、pyplot.grid を使う。 例 import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2 …

no image

tex で小文字のL(リットル)記号を入力する方法

tex で小文字のL(l)リットル記号を入力するには、\ell を使う。通常の小文字の l は、\\l であるのに注意。 例 5 \\ell 結果

no image

X(twitter) 時期を指定して検索する方法

X/Twitter の検索窓に次のように打ち込むことで、条件を指定して、絞り込んだポストを表示することができる。 日付を指定する since:2022-02-22 until:2022-02-23 あ …