C++ c++;使用前导零将Int保存到字符串,不显示它们
我可以格式化C++ c++;使用前导零将Int保存到字符串,不显示它们,c++,string,int,leading-zero,C++,String,Int,Leading Zero,我可以格式化Int以显示带前导零的数字,但我不知道如何将带零的Int保存为字符串 原因:正在加载以“.0001”…0002”结尾的图像文件。。。“.0059”等 我有这个,但不起作用: int a; for(int i = 1; i < imgArraySize + 1; i++) { cout << setw(4) << setfill('0') << i << '\n'; cin >> a; strin
Int
以显示带前导零的数字,但我不知道如何将带零的Int
保存为字符串
原因:正在加载以“.0001”…0002”结尾的图像文件。。。“.0059”
等
我有这个,但不起作用:
int a;
for(int i = 1; i < imgArraySize + 1; i++)
{
cout << setw(4) << setfill('0') << i << '\n';
cin >> a;
string aValue = to_string(a);
imageNames.push_back(string("test_images" + aValue + ".jpg"));
}
inta;
对于(int i=1;i cout您可以使用
std::ostringstream ss;
ss可能的重复项即将发布相同的内容:/只是看到问题太晚了为什么std::stringstream
而不是std::ostringstream
?
std::ostringstream ss;
ss << std::setw(4) << std::setfill('0') << a;
std::string str = ss.str();
std::cout << str;