bbqtruck
March 6th, 2006, 02:01 PM
im starting to get confused. i would appriciate it if someone could help me with my noobish understandings...
1. when do i use string::size_type vs using the iterator for string?
for example, i would like to examine each character in a string. therefore i would do something like
int index = 0;
while ( index < mystring.size)
{
cout << mystring.at(stringindex);
}
now i could also print out each character in a string via the iterator?
for(myiterator = st1.begin(); myiterator != st1.end(); myiterator ++)
{
if( *myiterator == 'h')
{
do something
}
}
///////
i guess when to find out the size or length or get what is in a particular space in a string, use the size_t....when using a string function, use the iterator???
1. when do i use string::size_type vs using the iterator for string?
for example, i would like to examine each character in a string. therefore i would do something like
int index = 0;
while ( index < mystring.size)
{
cout << mystring.at(stringindex);
}
now i could also print out each character in a string via the iterator?
for(myiterator = st1.begin(); myiterator != st1.end(); myiterator ++)
{
if( *myiterator == 'h')
{
do something
}
}
///////
i guess when to find out the size or length or get what is in a particular space in a string, use the size_t....when using a string function, use the iterator???