TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: DARRELL HNIZDOR
from: KURT KUZBA
date: 1997-11-11 01:31:00
subject: thanks

DH>   Can you tell me if there is a simple way to put
DH>   a string into a variable other than strcpy?
DH>   I know this doesn't work:
DH>   char a[]= "this string";
DH>   char b[20];
DH>      b=a;
   Neither b nor a is an Lvalue after initialization, so that
   won't work. If you want to use fixed length strings, you
   may use structs, with which simple assignment will work.
   Since this is C++, however, and not C, you may also create
   a string class which will allow overloading of the
   assignment operator. You would still be using the strcpy() or
   sprintf() to perform the actual transfer of data from one
   array to the other, but it would be hidden from you at the
   coding level, only being a concern at the class level.
   To use structs:
#include 
typedef struct { char S[128]; } MyString;
int main(void)
{
   MyString szA = { "A test string" };
   MyString szB = { "B test string" };
   MyString szTemp;
   cout << "szA = " << szA.S << '\n' << "szB = " << szB.S << endl;
   szTemp = szA;
   szA = szB;
   szB = szTemp;
   cout << "szA = " << szA.S << '\n' << "szB = " << szB.S << endl;
   return 0;
}
> ] I am Elvis of Borg. Thank you... Thank you very much........
---
---------------
* Origin: *YOPS ]I[* 3.1 GIG * RA/FD/FE RADist * Milwaukee, WI (1:154/750)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.