Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;使用前导零将Int保存到字符串,不显示它们_C++_String_Int_Leading Zero - Fatal编程技术网

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;icout您可以使用

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;