streamで%02dっぽいことをやる方法

#include 
#include 
#include 
using namespace std;
int main()
{
	int i=3;
	std::ostringstream oss;
	oss << setfill('0') << setw(2) << i;
	std::string name;
	name = "hogehoge" + oss.str();
	cout << name << endl;
	return 0;
}

実行結果は

hogehoge03

setfillで0で埋め、setwで幅2桁を指定する。

コメントを残す

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