I have a direct3d project that uses D3DXCreateTextureFromFile() to load some images. This function takes a LPCWSTR for the path to file. I want to load a series of textures that are numbered consecutively (ie. MyImage0001.jpg, MyImage0002.jpg, etc) But c++'s crazy strings confuse me.
How do i:
for(int i=0; i < 3;i++)
{
//How do I convert i into a string path i can use with D3DXCreateTextureFromFile?
}
Edit:
I should mention I am using Visual Studio 2008's compiler
One option is std::swprintf
:
wchar_t buffer[256];
std::swprintf(buffer, sizeof(buffer) / sizeof(*buffer),
L"MyImage%04d.jpg", i);
You could also use a std::wstringstream
:
std::wstringstream ws;
ws << L"MyImage" << std::setw(4) << std::setfill(L'0') << i << L".jpg";
ws.str().c_str(); // get the underlying text array
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With