delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/02/13:38:10

From: Forsberg Sakari <zacu AT cc DOT tut DOT fi>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Convert String to char *
Date: 2 Nov 1999 17:59:37 GMT
Organization: Tampere University of Technology
Lines: 22
Message-ID: <7vn8q9$bog$1@baker.cc.tut.fi>
References: <7vn6sc$7fh$1 AT nnrp1 DOT deja DOT com>
NNTP-Posting-Host: assari.cc.tut.fi
X-Trace: baker.cc.tut.fi 941565577 12048 130.230.10.21 (2 Nov 1999 17:59:37 GMT)
NNTP-Posting-Date: 2 Nov 1999 17:59:37 GMT
User-Agent: tin/pre-1.4-981225 ("Volcane") (UNIX) (OSF1/V4.0 (alpha))
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Nicolas Blais <nicblais AT hotmail DOT com> wrote:
> How do I convert a String to a character array *?

errr.... I remember a function c_str()

string tempstring = "hiiohei";
char tempchar[20];
strcpy( tempchar, tempstring.c_str() );

just remember to check if the string is short enough
or use 

int CHAR_LENGHT;
string tempstring = "hiiohei";
char tempchar[CHAR_LENGHT+1];
strncpy( tempchar, tempstring.c_str(), CHAR_LENGHT );
tempchar[CHAR_LENGHT] = '\0';

or check string size with function size();

**      Sakari Forsberg zacu AT cc DOT tut DOT fi       **
** Information: finger zacu AT assari DOT cc DOT tut DOT fi **

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019