In C++ when you're passing an array of char when instantiating a class, is it possible to put a cap on the bytes that are copied as to prevent an overflow if you're uncertain of the number of characters coming in?
My implementation is not based on user input so I know it's going to be fine, but I'm wondering for general knowledge.
e.g. (from this post)
class test2 {
char name[40];
public:
test2() : name("Standard") {};
void display() { cout << name << endl; }
};
e.g. (edited version of this post)
class test2 {
char name[40];
public:
test2(const char *charsComingIn) : name(charsComingIn) {};
void display() { cout << name << endl; }
};
As a sidenote, I haven't tested the second example but that's the gist of what I'm trying to do at the moment. Any corrections are welcome to concept of implementation.