[C++]演算子で文字列を結合するサンプル

2021年5月20日

書式
文字列A +文字列B
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <iostream>
using namespace std;
int main() {
string strA = "AA";
string strB = "123";
cout <<"result1: "+ (strA + strB) << endl;
cout << "result2: "+(strA + "456") << endl;
return 0;
}
#include <iostream> using namespace std; int main() { string strA = "AA"; string strB = "123"; cout <<"result1: "+ (strA + strB) << endl; cout << "result2: "+(strA + "456") << endl; return 0; }
#include <iostream>
using namespace std;

int main() {
      string strA = "AA";
      string strB = "123";

      cout <<"result1: "+ (strA + strB) << endl; 
      cout << "result2: "+(strA + "456") << endl; 

      return 0;
}

結果
result1: AA123
result2: AA456

C++

Posted by arkgame