substr crash

I've been trying to split a string into 6 parts using substr. For one reason or another I seem to crash the program every time I try doing so. I am a little bit stumped about how to work around this problem. If anyone could advice that would be helpful and much appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
string code(string work)
{
		string data(300,'\0');
		data = work;
		string out;
		string unbreak;
		vector <string> ram;
		ram.resize(6);
		ram.reserve(36);
		unbreak = data.substr(0,32);
		//ram [0] = unbreak;
		
		unbreak = data.substr(32,32);
		//ram [1] = unbreak;
		
		unbreak = data.substr(64,32);
		//ram [2] = unbreak;
		
		unbreak = data.substr(96,32);
		//ram [3] = unbreak;

		unbreak = data.substr(128,32);
		//ram [4] = unbreak;
		
		unbreak = data.substr(160,32);
		//ram [5] = unbreak;
		
		return out;// ignore this
}
Line 3 is pointless because you just overwrite it on line 4, and you never check to make sure work is long enough for your operations.
Topic archived. No new replies allowed.