www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/27/16:30:31

From: "Chia" <chia AT top DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: String to (char *)
Date: Mon, 27 Jul 1998 15:02:16 -0500
Organization: 404 Software
Lines: 28
Message-ID: <6pinr0$alj@nnrp1.farm.idt.net>
NNTP-Posting-Host: flex-3.top.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I've been programming C++ and Allegro.  I have a String called, "TheText" in
one of my classes which I want to print to the screen with "textout()."

However, the textout() function only does (unsigned char *)'s.

I am lost when it comes to how to convert the String to this, and without
doing that I can't print the text.  If someone could help it'd be great.

I've tried a simple typecast:  (char *)TheText,  and that didn't compile.

I then looked at the _string.h header and found a function, "chars()".  This
returns a (const char *).

So I tried:  (char *)TheText->chars();  This compiled, but printed garbage
on the screen.

So I tried a:  const_cast<char *>(TheText->chars()) which immediately
crashed the program.

The book I've been using says that a String class has a function called
c_str() which returns a (char *).  I tried that but the String class
apparently didn't have the function.

Thanks!

// chia AT top DOT net -- http://www.top.net/chia/


- Raw text -


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