Append?

For some reason, append won't work on the strings...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Protection{
	public:
		char* name;
		string* filter;
		int version;
		ProtectionType ptype;
		Protection(char* n, string f, ProtectionType p, int v)
		{
			name = n;
			ptype = p;
			version = v;
			for(int i=0; i<(f.length()/3); i++) {
				filter[i].append(f.c_str(),((i*3)+3)); ///////////////////////////////////////////////////////////////////////
			}
		}
};

is the class where it's being called.
Protection x("Nelson", "Abso1uTPwrInsta11U$E1234qwerDS", ANTISPAM, 1); is how I'm calling it-and ANTISPAM is valid. I used throw...catch to learn that I was using append wrong somehow...can anyone help?
You are using filter, which is a pointer to a string, before it is initialized. This code
should be crashing on line 13, right?
yeah, it crashes there.
So I'm not quite sure what to do-a vector of strings? Or
 
filter = new string[(f.length/3)];
if I do this-between setting version and the for loop start-it'll stay allocated, amirite?
Last edited on
When given a choice between a vector<string> and a dynamically allocated array of strings, there is never a reason to go with the latter. vector<> implements a dynamic array in the first place, and thus the two choices are equivalent. The difference is that vector<> manages the memory for you whereas with the dynamic array you have to manage it.
Great, thank you! I'll use the vector-it suits my needs better.
Topic archived. No new replies allowed.