   SDL n00b question about std::string
  Hey guys I feel like a complete fool asking this silly of a question but I am learning SDL (already have a B.S. in Computer Science) and am having trouble with std::string.Visual Studio 2010 is saying that when I declare a string value (i.e. string myString) that "string" is an undeclared identifier even though I have tried it including the string.h file, the stdlib.h file, declaring the string as std::string, etc.Like I said, this is probably me just overlooking something very small but I thought you guys might be able to assist me with it.   
  What is the exact error you get? Can we see some sample code?   ;  #include <SDL.h>#include <string.h>class player{private:int width;int height;SDL_Rect src;SDL_Rect dst;SDL_Surface* sprite;public:player();void setSurface(string);void Update();void Draw(int, int, int, int,int, int, SDL_Surface*, SDL_Surface*);};player::player(){width = 32;height = 32;}void player::setSurface(string image){sprite = SDL_LoadBMP(image);}That is the code I have for a generic player in the game (only part of it actually) and here is the error output from the two string declarations dealing with the setSurface function...1>c:\documents and settings\jlamoureux\my documents\visual studio 2010\projects\sdlgame1\sdlgame1\player.h(15): error C2061: syntax error : identifier 'string'1>c:\documents and settings\jlamoureux\my documents\visual studio 2010\projects\sdlgame1\sdlgame1\player.h(27): error C2065: 'string' : undeclared identifier1>c:\documents and settings\jlamoureux\my documents\visual studio 2010\projects\sdlgame1\sdlgame1\player.h(27): error C2146: syntax error : missing ')' before identifier 'image'1>c:\documents and settings\jlamoureux\my documents\visual studio 2010\projects\sdlgame1\sdlgame1\player.h(27): error C2761: 'void player::setSurface(void)' : member function redeclaration not allowed1>c:\documents and settings\jlamoureux\my documents\visual studio 2010\projects\sdlgame1\sdlgame1\player.h(27): error C2059: syntax error : ')'1>c:\documents and settings\jlamoureux\my documents\visual studio 2010\projects\sdlgame1\sdlgame1\player.h(28): error C2143: syntax error : missing ';' before '{'1>c:\documents and settings\jlamoureux\my documents\visual studio 2010\projects\sdlgame1\sdlgame1\player.h(28): error C2447: '{' : missing function header (old-style formal list?)1>c:\documents and settings\jlamoureux\my documents\visual studio 2010\projects\sdlgame1\sdlgame1\gameevents.h(36): error C2660: 'player::setSurface' : function does not take 1 arguments   ;  Well, firstly you should be including <string> and secondly, unless you use a using declaration or something you need to go:void player::setSurface(std::string image)(And a const reference to it would be better still!   ;  You need:#include <string>Not:#include <string.h>   ;  Oh sweet thanks mates, sometimes I can't stand careless mistakes like that...Quote:Original post by BigJim(And a const reference to it would be better still!Such as this?#include <SDL.h>#include <string>class player{private:int width;int height;SDL_Rect src;SDL_Rect dst;SDL_Surface* sprite;public:player();void setSurface(std::string*);void Update();void Draw(int, int, int, int,int, int, SDL_Surface*, SDL_Surface*);};player::player(){width = 32;height = 32;}void player::setSurface(std::string *image){sprite = SDL_LoadBMP((char*)"ampersand"image);}On a side note: how do I put code into blocks? and how do I properly display the ampersand?   ;  Ok well now I have the const char reference like you were talking about BigJim but I am having trouble passing in my parameter to the setSurface function...Here is the function in my player.h filevoid player::setSurface(const char image){sprite = SDL_LoadBMP("ampersand"image);}I have instantiated player in another file called gameEvents.h which makes a call in it's Load method to player.setSurface("player.bmp");void gameEvents::Load(){background = SDL_LoadBMP("groundBig.bmp");player.setSurface("player.bmp");}and I am getting this error:error C2664: 'player::setSurface' : cannot convert parameter 1 from 'const char [11]' to 'const char'   ;  What he meant was to use a const std::string& as a parameter:void player::setSurface(const std::string& image){   sprite = SDL_LoadBMP(image.c_str());}// Elsewhere:player.setSurface("blah")That was the compiler doesn't have to create a temporary std::string and then make another copy, it can just use one.To display code in boxes, use [ source ] [ /source ] tags (Without the spaces). To display ampersands in non-source tags, you can use &amp;   ;Quote:Original post by Evil SteveWhat he meant was to use a const std::string& as a parameter:*** Source Snippet Removed ***That was the compiler doesn't have to create a temporary std::string and then make another copy, it can just use one.Oh ok, thanks, I was having trouble with the SDL_LoadBMP() function wanting a const char* passed to it, but this helps alot!Quote:Original post by Evil SteveTo display code in boxes, use [ source ] [ /source ] tags (Without the spaces). To display ampersands in non-source tags, you can use &And this possibly helps even more!!Thanks again.   ;  Man I don't like being a n00b when it comes to this kind of stuff.I am now having problems setting the color key of my loaded BMP file.void player::setSurface(const std::string& image){sprite = SDL_LoadBMP(image.c_str());SDL_SetColorKey(sprite, SDL_SRCCOLORKEY, SDL_MapRGB(sprite->format, 200, 0, 200));}Any ideas?   