alternate to string.data()

This is a discussion on alternate to string.data() within the C++ Programming forums, part of the General Programming Boards category; I was having an error, the ilLoadImage function wont take a const char*, only a char*, so i fixed it ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    411

    alternate to string.data()

    I was having an error, the ilLoadImage function wont take a const char*, only a char*, so i fixed it like this. Is there another way to do it? I removed all the other stuff from the funtion so you can read it easily.

    Code:
    unsigned int cRenderEngine::LoadTexture(string path, short size) {
    
    	--code--
    
    	char * temp = new char[path.length()];
    	for(int i = 0; i < path.length(); i++)
    		temp[i] = path[i];	
    	ilLoadImage(temp);
    
    	--code--
    
    }

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Use strcpy in <cstdlib>
    Code:
    char* temp = new char[path.length() + 1];
    strcpy(temp, path.c_str());
    ilLoadImage(temp);
    delete [] temp;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. alternate to an array???
    By Loic in forum C++ Programming
    Replies: 21
    Last Post: 07-08-2008, 08:59 PM
  2. alternate to string streams
    By MicroFiend in forum C++ Programming
    Replies: 9
    Last Post: 04-30-2008, 02:03 AM
  3. Alternate energy sources
    By Govtcheez in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 02-02-2005, 06:07 PM
  4. read from alternate file on PC
    By brooklyn1126 in forum C++ Programming
    Replies: 1
    Last Post: 05-15-2004, 10:30 PM
  5. alternate function to sprintf
    By Eber Kain in forum C++ Programming
    Replies: 5
    Last Post: 12-27-2002, 09:38 PM

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