質問

I need to create files with generated names. I use boost::lexical_cast to transform integers to std::string. Is it a possibility to get string with padding zeros; I have no c++11 tools, just everything that MSVS 2008 supports.

Example :

int i = 10;
std::string str = boost::lexical_cast<std::string>(i);

// str = "10"
// expect str = "000010"

p.s. don't suggest to use sprintf please.

役に立ちましたか?

解決

Why boost::lexical_cast? Use std::stringstream

std::ostringstream ss;
ss << std::setw(6) << std::setfill('0') << i;
const std::string str = ss.str();

他のヒント

You could use std::ostringstream with the normal stream manipulators for formatting.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top