Splitting a string

I'm attempting to split a string like this

[label] opcode [arg1] [arg2]

The label and arguments are optional but there is always an opcode and there is always whitespace where the label is if it isn't there. Right now I have this:

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
while (myFile.good())
	{
		getline(myFile, line, '\n');
		
		if (line[0] == '#')
		{
			continue;
		}
		
		
		if (line[0] != '\t' && line[0] != ' ')
		{
			
			string delimeters = "\t,";

			int current;
			int next = -1;

			do
			{
				current = next + 1;
				next = line.find_first_of( delimeters, current);
				label = line.substr( current, next - current );
				cout << label << endl;
			}
			while (next != string::npos);
		}
		
		
	}


The cout << label << endl; is there to see what I have in there. The output I'm getting is:

1
2
3
4
5
6
7
8
TOP
NOP
VAL
INT 0
TAN
LA
2
1


When I should just be getting:
1
2
3
TOP
VAL
TAN


Here is the original text file I'm reading in from
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Sample Input

	LA 1,3
	LA 2,1
TOP	NOP
	ADDR 3,1
	ST 3, VAL
	CMPR 3,4
	JNE TOP
	P_INT 1,VAL
	P_REGS
	HALT
VAL	INT 0
TAN	LA	2,1
Why are you using the do-while loop? If all you're doing is extracting labels, and you can't have more than one label per line... why loop through the line after you've already found a label?
Topic archived. No new replies allowed.