未分類

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 で差集合の記号を入力する方法

\setminus を使う。 例 $A \setminus B$ 結果

no image

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

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

no image

python3 で、ファイルの文字列の1行目を出力する

ファイルを読み込んで、1行目だけをコンソールに出力するには readlines() を使う。 例 f = open(“data.txt”) lines = f.readlines() print(li …

no image

tex で脚注を表示する方法

\footnote を使う。 例 \footnote{this is a footnote.} 結果

no image

tex で和集合を入力する方法

\bigcup を使う。 例 $\displaystyle \bigcup _ {i \in \Lambda} A_i $ 結果