🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #327

Re: newbie: strings versus char*

#327
From: ohaya
Date: Mon, 27 Dec 1999 00:00
34 lines
1879 bytes
tagus18/maria,

From your post, I'm not exactly clear what you are asking for, but it
sounds like you have two problems:

1) Reading input into a dynamic char array

2) The maximum keyboard buffer (128 chars?).

Here's a small sample that'll take care of #1 above, but it still is
limited to the keyboard buffer maximum:

#include                     // include iostream
#include                     // include string
using namespace std;

int main()
{
string x;                    // declare a C++ string

cin >> x;                    // input to the C++ string

cout << "You entered [" << x << "]" << endl;  // show what was input

char * y = new char[strlen(x.c_str() + 1]; // create C char array
strcpy(y, x.c_str());    // copy C++ string to C char array

cout << "y=[" << y << "]" << endl;         // show C char array
}



* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
Technical Details
Message-ID: <32bd4fa0.67ff56dc@usw-ex0101-008.remarq.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <8485tm$cfg$1@nnrp1.deja.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1061d2,fcdf60e52711dfec
X-Google-Attributes: gid1061d2,public
X-Google-Thread: 114592,fcdf60e52711dfec
X-Google-Attributes: gid114592,public
From: ohaya <ohayaNOohSPAM@yahoo.com.invalid>
Subject: Re: newbie: strings versus char*
Date: 1999/12/27
Message-ID: <32bd4fa0.67ff56dc@usw-ex0101-008.remarq.com>
X-Deja-AN: 565583088
References: <8485tm$cfg$1@nnrp1.deja.com>
Bytes: 1009
X-Originating-Host: 204.178.186.10
X-Complaints-To: wrenabuse@remarq.com
X-Trace: WReNphoon4 946366004 10.0.2.8 (Mon, 27 Dec 1999 23:26:44 PST)
Organization: http://www.remarq.com: The World's Usenet/Discussions Start Here
NNTP-Posting-Date: Mon, 27 Dec 1999 23:26:44 PST
Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cpp.non-technical
X-Wren-Trace: eH1YcHFoL2UuMmF0YTxcbW5mYnc2ejJmOCMiKjo4M2U8KmUqPWw4