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)
|