11
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

##sstreamをincludeしてostringstreamを使うのがはやい。
大切なのは、この3行。

	ostringstream ss;
	ss << a;
	str = str + ss.str();

aがint型、strがstring型。つまり、strに数値aを文字列として追加してる。

以下、str(t)とa(5)を足しているコード。

#include <string>
#include <sstream>
#include <iostream>
using namespace std;

int main()
{
	string str;
	str.push_back('t');
	int a = 5;
	ostringstream ss;
	ss << a;
	str = str + ss.str();
	std::cout << str << std::endl;
}

t5が結果としてでてくる。

11
7
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?