iterator and for loop

Can you help with this? I am having loop where I am parsing argument. My problem is that I don't know how to access the characters under (*it).

So I need to replace (*it)[n] for valid syntax used in C++03.
For example the (*it) refers to word "bla{y:12-15}blabla{x:124-}blabla"
other variations are "{y:12-15}blabla{x:124-}blabla" or "bla{y:12-15}blabla{x:124-}" or "{y:12-15}blabla{x:124-}"
so if it would be char * arg; I would refer it like arg[n] but I cannot do it with iterator. So I am curious how to do it correctly.

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
it++; i++; // read next argument
std::istringstream regex((*it));
int prefixn=0; // position of prefix
int sufixn=sizeof((*it)); // position of suffix
char * first; char * second;
for (int n=0; n<sizeof((*it)); n++){
	if( (*it)[n] == '{')
		{
		if (!prefixn) // set the first position
			{
			prefixn=n;
			for (; (*it)[n] <> '}'; n++)
			first+=(*it)[n];
			}
			else
			{
			for (; (*it)[n] <> '}'; n++)
			second+=(*it)[n];
			}
		}
		if( (*it)[n] == '}')
		{
		sufixn=n; // set the last position
		}
	}
for() loops' condition, lines 12 and 17: there is no operator <> in C++.
Perhaps you meant to use operator != as in:

for (; (*it)[n] != '}'; n++)
Ah, so there was not problem in the expression (*it)[n] . Thanks.
Is there way how to watch the value of (*it)[n] in Visual Studio during watch?
I can add (*it)[n] to Watch pan but it will display: Error: Overloaded operator not found
I am using this loop:
for (std::vector<std::string>::iterator it = raw_args.begin(); it != raw_args.end(); ++it)
I want to get characters one by one from the vector.

Now I have this problem:
When prefix is char * = "";
and (*it) is some word, eg. "one"
and n is 0,
I need prefix to be set to "o". How to do it?
This:
prefix=prefix + (*it)[n];
sets prefix to "0"
Last edited on
Simple explanation: the prefix variable is a pointer to char, it is not a "real" string.

Simple solution: use an std::string instead of char*, as in:

1
2
std::string prefix = "";
// now prefix + (*it)[n] will concatenate as you (probably) intend 

Ok, thanks.
Last edited on
Registered users can post here. Sign in or register to post.