Results 1 to 3 of 3

Thread: char* problem

  1. #1

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362

    char* problem

    How can I do that witout having an error, I want to put a char* to char[30].

    Example :
    Code:
    char sNom[30];
    //************This is somewhere else
    string s = sTexteAnalyser.substr(0,sTexteAnalyser.find('\n',0));
    	
    sNom = s.c_str() ;
    Error : cannot convert from "const char*" to "char[30]"

    Tell me what to do please

  2. #2
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Try:
    Code:
    #include <cstring>
    using namespace std;
    
    //...
    
    strcpy(sNom, s.c_str());
    Beware, you can crash your program if the .c_str() returns a string longer than 30 characters.
    Alcohol & calculus don't mix.
    Never drink & derive.

  3. #3

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    THX YOU MAN

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width