# Iteration problem

Page 1 of 1

## 3 Replies - 2827 Views - Last Post: 08 December 2012 - 09:59 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=303275&amp;s=071e049bb8046d3a691ef859cbbb529d&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

Reputation: 7
• Posts: 236
• Joined: 31-July 09

# Iteration problem

Posted 08 December 2012 - 08:47 PM

Hi
I have this problem I am trying to find the v in the iteration now for some reason the iteration skips index 0.
I know theirs a logical solution to this but I'm a bit stuck any help would be appreciated

```string line = "v 0 2.928242206573486 0";

for( unsigned int i = 0; i < line.length(); i++ )
{
if( num = line.find( "v", i ) )
{
if( i == num )
{
cout << "V Numbers: " << i << endl;
}
}
}

```

Is This A Good Question/Topic? 0

## Replies To: Iteration problem

• D.I.C Lover

Reputation: 331
• Posts: 1,168
• Joined: 01-April 11

## Re: Iteration problem

Posted 08 December 2012 - 09:03 PM

"v" is a string, and there is no string matching that.
'v' is a char, and that maybe is what you should be looking for. I believe that's true, but I'm a C guy, NOT C++ - could be WAY off here. But see below.

Also, this part, looks either incomplete or incorrect.
``` if( num = line.find( "v", i ) )   //looks dodgy to me

```

If num is set to 0, won't that translate to the whole if(expression) being false?

Reputation: 7
• Posts: 236
• Joined: 31-July 09

## Re: Iteration problem

Posted 08 December 2012 - 09:45 PM

Hi
I changed my code to this this definetely works and finds v at 0

```string line = "v 0 2.928242206573486 0";

for( unsigned int i = 0; i < line.length(); i++ )
{

cout << line.at( i ) << endl;

if( 'v' == line.at( i )  )
{
cout << "V Numbers: " << i << endl;
}
}

```

• D.I.C Lover

Reputation: 331
• Posts: 1,168
• Joined: 01-April 11

## Re: Iteration problem

Posted 08 December 2012 - 09:59 PM

Excellent - that looks like robust and clear code!