[C++]append()で文字列を追加するサンプル
書式
文字列A.append(文字列B)
使用例
#include <iostream>
using namespace std;
int main() {
string strA = "arkgame";
//追加する文字列
string resA = strA.append(".com");
cout <<"result1: "+ resA << endl;
string strB = "arkgame.";
//追加する文字列2個
string resB = strB.append(".com",3);
cout <<"result2: "+resB << endl;
string strC = "arkgame";
//位置 文字数
string resC = strC.append("勉強",0,3);
cout <<"result3: "+resC << endl;
return 0;
}
#include <iostream>
using namespace std;
int main() {
string strA = "arkgame";
//追加する文字列
string resA = strA.append(".com");
cout <<"result1: "+ resA << endl;
string strB = "arkgame.";
//追加する文字列2個
string resB = strB.append(".com",3);
cout <<"result2: "+resB << endl;
string strC = "arkgame";
//位置 文字数
string resC = strC.append("勉強",0,3);
cout <<"result3: "+resC << endl;
return 0;
}
#include <iostream> using namespace std; int main() { string strA = "arkgame"; //追加する文字列 string resA = strA.append(".com"); cout <<"result1: "+ resA << endl; string strB = "arkgame."; //追加する文字列2個 string resB = strB.append(".com",3); cout <<"result2: "+resB << endl; string strC = "arkgame"; //位置 文字数 string resC = strC.append("勉強",0,3); cout <<"result3: "+resC << endl; return 0; }
実行結果
result1: arkgame.com
result2: arkgame..co
result3: arkgame勉