Error with std::out_of_range, Can someone help?

Here is the console:
varr HelloWorld, Hello, world!;
prnt HelloWorld;
quit
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::substr
Aborted (core dumped)
Press ENTER to continue...


here is my main loop of code:
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
30
31
32
33
34
35
36
string argv = "";
	string line = "";
	while(line != "quit") {
		cin >> line;
		argv += line;
	}
	
	for(int i = 0; i < sizeof(argv) - 4; i++) {
		if(argv.substr(i, 4) == "varr") {
			string name = "";
			int x = i +1;
			for(x; argv.substr(x) != ","; x++) {
				name += argv.substr(x);
			}
			string val = "";
			x++;
			for(x; argv.substr(x) != ";"; x++) {
				val += argv.substr(x);
			}
			
			vars[name] = val;
			i = x;
		} else if(argv.substr(i, 4) == "prnt") {
			string name = "";
			int x = i +1;
			for(x; argv.substr(x) != ";"; x++) {
				name += argv.substr(x);
			}
			
			cout << vars[name];
			i = x;
		}
	}
	
	cin.get();
	cin.sync();


Okay so now I'm in debug and at that error I get:
Program Received signal SIGABRT
Stack trace is available in the 'Call Stack' tab
Last edited on
Your loop condition on line 8 makes no sense. Presumably you meant argv.size() or argv.length() and not sizeof(argv).

My guess is that one of the:
1
2
argv.substr(i, 4)
argv.substr(x)
statements is trying to access out of the length of the string.

http://www.cplusplus.com/reference/string/string/substr/
says:

If pos is greater than the string length, an out_of_range exception is thrown.
Topic archived. No new replies allowed.