struct test
{
char[20] chName;
};
How do I assign a string to name... e.g. the following will not compile:
test mytest;
myTest.chName = "MyName";
Can anyone offer any help? Many thanks.
struct test
{
char[20] chName;
};
How do I assign a string to name... e.g. the following will not compile:
test mytest;
myTest.chName = "MyName";
Can anyone offer any help? Many thanks.
test mytest;strcpy(myTest.chName,"MyName");
#include <string>struct test{ std::string chName;};test mytest;myTest.chName = "MyName";
struct test{ char chName[20];};test mytest;strcpy(myTest.chName, "MyName");
struct test{ std::string name;}test mytest;mytest.name = "MyName";
Quote:Original post by TheAdmiral
It's a little irresponsible to propagate the use of the deprecated strcpy function.
jpbb, I strongly suggest you use std::string for your purposes. It is safer, easier and laden with wonderful features.
If that's not possible, then you should use strncpy. It's not without its problems, but it can help to avoid buffer overruns and hence exploitable code.
Regards
Admiral