int BMP::FindTexture(std::string Filename)
{
int i;
for (i = 0;i < TexCount; i++)
{
if (Filename == BMPTexture.FileName) // std::string works with operator==. char*'s do not.
{
return i;
}
}
return -1;
}
🔒 Locked
problem with std::string
Advertisement
Original Post
i got a compile error with this code at the if statement --------------------Configuration: Maia - Win32 Debug-------------------- Compiling... BMP.cpp D:\Shooter\Maia\BMP.cpp(114) : error C2678: binary '==' : no operator defined which takes a left-hand operand of type 'class std::basic_string,class std::allocator >' (or there is no acceptable conversion) Error executing cl.exe. BMP.obj - 1 error(s), 0 warning(s) [Edited by - Fruny on December 19, 2004 3:09:30 PM]
OK - first things first - closing tags aren't _source, it's /source.
Secondly - the error message is telling you that there is no comparison defined for Filename and BMPTexture.FileName.
So - what is BMPTexture? Is it an array of objects containing a public std::string called Filename? If you could show the definition it would help.
Next : if you're passing a parameter like this, you should use:
int BMP::FindTexture(const std::string& Filename) const
It's a const parameter, as you don't alter it. Passing by reference means no temporaries are created. And it's a const function (the trailing const) as it doesn't alter the BMP object.
Jim.
Secondly - the error message is telling you that there is no comparison defined for Filename and BMPTexture.FileName.
So - what is BMPTexture? Is it an array of objects containing a public std::string called Filename? If you could show the definition it would help.
Next : if you're passing a parameter like this, you should use:
int BMP::FindTexture(const std::string& Filename) const
It's a const parameter, as you don't alter it. Passing by reference means no temporaries are created. And it's a const function (the trailing const) as it doesn't alter the BMP object.
Jim.
theres the dec. for my structure
i think that it might be a problem with the struct. i dont think it is workin rite. when i type BMPTexture. i dont see a list of the variables in the struct.
struct BMPTex { GLuint imageDataNear; GLuint imageDataLin; GLuint imageDataMip; std::string FileName;};i think that it might be a problem with the struct. i dont think it is workin rite. when i type BMPTexture. i dont see a list of the variables in the struct.
#include <iostream>#include <vector>struct BMPTex { GLuint imageDataNear; GLuint imageDataLin; GLuint imageDataMip; std::string FileName;};class BMP{public: // constructor BMP(); BMP(int TexCount); // deconstructor ~BMP(); // public functions BOOL LoadGLTextures (std::string Filename, int FileNum); void GenTex (int FileNum); void BindNear (int FileNum); void BindLin (int FileNum); void BindMip (int FileNum); int FindTexture (const std::string& Filename) const; void SetTextureName (int FileNum, std::string fileName) { BMPTexture[FileNum].FileName = fileName; } private: std::vector<BMPTex> BMPTexture; int TexCount;};
heh no lol thx it cmopiles now !!
shit lol it doesnt compile cause its having some troubles with the std::string
--------------------Configuration: Maia - Win32 Debug--------------------
Compiling...
BMP.cpp
D:\Shooter\Maia\BMP.cpp(20) : error C2440: 'type cast' : cannot convert from 'class std::basic_string,class std::allocator >' to 'char'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
D:\Shooter\Maia\BMP.cpp(24) : error C2664: 'auxDIBImageLoadA' : cannot convert parameter 1 from 'class std::basic_string,class std::allocator >' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.
Maia.exe - 2 error(s), 0 warning(s)
AUX_RGBImageRec *LoadBMP(std::string Filename) // Loads A Bitmap Image{ FILE *File=NULL; // File Handle //if (Filename) // Make Sure A Filename Was Given //{ // return NULL; // If Not Return NULL //} File=fopen(Filename,"r"); // Check To See If The File Exists if (File) // Does The File Exist? { fclose(File); // Close The Handle return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer } return NULL; // If Load Failed Return NULL}--------------------Configuration: Maia - Win32 Debug--------------------
Compiling...
BMP.cpp
D:\Shooter\Maia\BMP.cpp(20) : error C2440: 'type cast' : cannot convert from 'class std::basic_string
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
D:\Shooter\Maia\BMP.cpp(24) : error C2664: 'auxDIBImageLoadA' : cannot convert parameter 1 from 'class std::basic_string
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.
Maia.exe - 2 error(s), 0 warning(s)
std::string has no implicit conversion to C-style char*. Instead it provides a c_str() member function which returns a C-style const char*. Use this member function to convert your std::string to a const char* which can be passed to fopen. You might also want to look into iostreams, which are C++'s typesafe classes for input/output.
Enigma
Enigma
Sorry for disappearing off!
This next one is because there is no implicit conversion from string to char*, and fopen wants a char* input.
If you use Filename.c_str() instead of Filename, it turns it into a char array.
You might have the same thing with AuxDibImageLoad.
Jim.
Edit : darn, beaten again!
This next one is because there is no implicit conversion from string to char*, and fopen wants a char* input.
If you use Filename.c_str() instead of Filename, it turns it into a char array.
You might have the same thing with AuxDibImageLoad.
Jim.
Edit : darn, beaten again!
nice!! it works now lol. Just one thing.
im not sure how this works exactly
std::vector BMPTexture;
if i were to use that like BMPTexture[7].FileName, would that work? because i will need an array of those but currently it isnt an array rite? So do i have to declare it as an array or use the "new" statment to make an array of it at runtime?
thx jake
im not sure how this works exactly
std::vector
if i were to use that like BMPTexture[7].FileName, would that work? because i will need an array of those but currently it isnt an array rite? So do i have to declare it as an array or use the "new" statment to make an array of it at runtime?
thx jake
so how do i use the resize and push_back members ?
thx man you've been a great help
jake
jake
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement