Jump to content
  • Advertisement
Sign in to follow this  
wforl

char and strings

This topic is 3963 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have the following IDirect3DTexture9* tex = 0; char* texFN = d3dxmtrls.pTextureFilename; HR(D3DXCreateTextureFromFile(gd3dDevice, texFN, &tex)); but i need to append something that i have in a string to texFN, such as the following std::string directory = "C:\somwhere\" char* texFN = d3dxmtrls.pTextureFilename; texFN = directory + texFN; how would i do this? im sure ive used the following in the past, but it wont work now std::string directory = "C:\somwhere\" char* texFN = d3dxmtrls.pTextureFilename; char temp[]; sprintf(temp, %s%s, directory.data(), texFN;

Share this post


Link to post
Share on other sites
Advertisement
1. You should be using std::string all over the place except where you absolutely have to use const char*
2. The member function to get a const char* from a std::string is c_str(), not data(). data() isn't guaranteed to giev you a null terminated string of const char's at all (As far as I'm aware)
3. Are you sure that d3dxmtrls.pTextureFilename is large enough to have "C:\somwhere\" prepended to it?
4. Define "Won't work now"
5. Are you passing that exct string ("C:\somwhere\") in like that, or are you escaping it? That won't even compile currently.
6. Any reason you're not using forward slashes instead (Which work on Win32 exactly the same as backslashes except for a few specific cases) and don't require escaping?

Something like this should work:
char* texFN = d3dxmtrls.pTextureFilename;
std::string strFilename = "C:/somewhere/";
strFilename += texFN;
HR(D3DXCreateTextureFromFile(gd3dDevice, strFilename.c_str(), &tex));
As would using a std::stringstream.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!