Sign in to follow this  
savail

Problem with vectors in visual c++ directX

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[i] != "null" && image[i] != " "). 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.
[code] 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[i] != "null" && image[i] != " ")
{
hr = D3DXCreateTextureFromFileEx(d3dDevice, image[i].c_str(), D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, 0xFFFFFFFF, &SrcInfo, NULL, &texture[i]);
if(!CheckHR(hr)) return false;
}
}

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

return true;
}[/code]

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:
[code]if(image[i][0] != 'n')
{
hr = D3DXCreateTextureFromFileEx(d3dDevice, image[i].c_str(), D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, 0xFFFFFFFF, &SrcInfo, NULL, &texture[i]);
if(!CheckHR(hr)) return false;
}[/code]
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this