string question

This is a discussion on string question within the C++ Programming forums, part of the General Programming Boards category; I am trying to load a file using a string as a file name. This is the class that uses ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    5

    string question

    I am trying to load a file using a string as a file name. This is the class that uses the string to load in the file.
    Code:
    class Texture
    {
    	int m_width;					//width of the image
    	int m_height;					//height of the image
    
    	unsigned char* m_pixels;		//pixel data
    public:
    	Texture(std::string fileName);
    	~Texture();
    
    	int getWidth();
    	int getHeight();
    
    	unsigned char* getPixels();
    };
    In the fuction for the drawer class, I create a new Texture, and supply a string for the file to load in. (only related code posted). m_currentLevel is a Level class.
    getFloorTexName() simply returns the string of the filename used for the floor texture.
    Code:
    std::string texName = m_currentLevel->getFloorTexName();
    Texture* texture = new Texture(texName);
    GLuint ID = loadTexture(texture);
    Using this code, the program compiles just fine, but I get this error when I run it.
    Access violation reading location 0x00000018.
    The compiler is pointing to this function in the <xstring> header file.
    Code:
    size_type size() const
    {	// return length of sequence
             return (this->_Mysize);
    }
    Am I not using the string class correctly? What is causing this error?

  2. #2
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Sounds like the same kind of problem you asked about earlier today. Check your pointers to string objects. My guess is that it's in getFloorTexName.
    Consider this post signed

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    5
    I am not using pointer for my strings. getFloorTexName() returns a string object, not a pointer. I'm going to step through my code and see if I can't see anything wrong.

    EDIT- ok I know what the problem is, I just don't know how to fix it, but I think I will try it on my own. (Shouldn't be too hard to figure out if I look at it for awhile.)
    Last edited by insanoflex; 01-21-2011 at 11:19 AM. Reason: update response

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 05:05 AM
  2. Reusing a string pointer question
    By chiefmonkey in forum C++ Programming
    Replies: 3
    Last Post: 05-06-2009, 05:53 PM
  3. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 04:58 PM
  4. String array question
    By gogo in forum C++ Programming
    Replies: 6
    Last Post: 12-08-2001, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21