Jump to content
  • Advertisement
Sign in to follow this  
savail

Problem with vectors in visual c++ directX

This topic is 2594 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

Hey
I wrote a function that reads addreses of images from file txt to create textures from them later. I'm puting the loaded data into vector<string> and I'm checking if the loaded data is "null" or " ". If it equals "null" or " " it should omit creating a texture but the program doesn't compile in this if instruction: if(image != "null" && image != " "). It returns: error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::basic_string<_Elem,_Traits,_Ax>' (or there is no acceptable conversion). In code::blocks such instruction: doesn't make any errors. How to repair these errors? I will be very grateful for help.
Graphics::Load()
{
D3DXIMAGE_INFO SrcInfo;
std::fstream plik( "sprites.txt", std::ios::in );
char pre[ 255 ];
char line[ 255 ];
std::vector<std::string> image;
while( !plik.eof() ) {
plik.getline( pre, 255, ' ' );
plik.getline( line, 255, '\n' );
image.push_back(line);
}
plik.close();
HRESULT hr;
for(int i = 0; i < image.size()-1; i++)
{
if(image != "null" && image != " ")
{
hr = D3DXCreateTextureFromFileEx(d3dDevice, image.c_str(), D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, 0xFFFFFFFF, &SrcInfo, NULL, &texture);
if(!CheckHR(hr)) return false;
}
}

hr = D3DXCreateSprite(d3dDevice, &sprite);
if(!CheckHR(hr)) return false;

return true;
}

Share this post


Link to post
Share on other sites
Advertisement
Test is against an empty string. So:

std::string empty_string("");
if( image != empty_string )
{
...
}

Share this post


Link to post
Share on other sites
but the word null is written in the file. I didn't mean the constant NULL. And unfortunately the same error occurs :/. I solved it by checking only the first character in string like:
if(image[0] != 'n')
{
hr = D3DXCreateTextureFromFileEx(d3dDevice, image.c_str(), D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, 0xFFFFFFFF, &SrcInfo, NULL, &texture);
if(!CheckHR(hr)) return false;
}

But if there is any other way to solve my problem I would be very grateful for help^^

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!