www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/03/23:45:27

From: Martin Ambuhl <mambuhl AT earthlink DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Convert String to char *
Date: Wed, 03 Nov 1999 12:56:43 -0500
References: <7vn6sc$7fh$1 AT nnrp1 DOT deja DOT com>
X-Posted-Path-Was: not-for-mail
X-Accept-Language: en
X-ELN-Date: 3 Nov 1999 17:56:31 GMT
X-ELN-Insert-Date: Wed Nov 3 10:05:01 1999
Organization: Nocturnal Aviation
Lines: 60
Mime-Version: 1.0
NNTP-Posting-Host: dialup-209.246.109.129.newyork2.level3.net
Message-ID: <3820775B.2DA4DFC9@earthlink.net>
X-Mailer: Mozilla 4.7 [en] (Win95; U)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com


Nicolas Blais wrote:
> 
> How do I convert a String to a character array *?

#include <_String.h>    // for obsolete libg++ String class
#include <string>       // for standard c++ string class
#include <iostream>

int main(void)
{
    const char *s;
    char hold[256];
    string ansi("This is an ansi C++ string");
    String gpp("This is an obsolete libg++ String");

    s = ansi.c_str();
    strcpy(hold, s);
    cout << "The string `ansi' is at " << (void *)&ansi << "\n"
        << "and prints as \"" << ansi << "\"\n"
        << "The char* s points to " << (void *)s << "\n"
        << "and prints as \"" << s << "\"\n"
        << "The char[] hold is at " << (void *)hold << "\n"
        << "and prints as \"" << hold << "\"\n" << endl;
    
    s = (const char *)gpp;
    strcpy(hold, s);
    cout << "The string `gpp' is at " << (void *)&gpp << "\n"
        << "and prints as \"" << gpp << "\"\n"
        << "The char* s points to " << (void *)s << "\n"
        << "and prints as \"" << s << "\"\n"
        << "The char[] hold is at " << (void *)hold << "\n"
        << "and prints as \"" << hold << "\"" << endl;
    
    return 0;
}


The string `ansi' is at 0xbd5e0
and prints as "This is an ansi C++ string"
The char* s points to 0xbfa9c
and prints as "This is an ansi C++ string"
The char[] hold is at 0xbd600
and prints as "This is an ansi C++ string"

The string `gpp' is at 0xbd5c0
and prints as "This is an obsolete libg++ String"
The char* s points to 0xc0218
and prints as "This is an obsolete libg++ String"
The char[] hold is at 0xbd600
and prints as "This is an obsolete libg++ String"


-- 
Martin Ambuhl	mambuhl AT earthlink DOT net

__________________________________________________________
Fight spam now!
Get your free anti-spam service: http://www.brightmail.com

- Raw text -


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