Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 19th, 2006, 12:58 PM   #11
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Find, for a vector (as I showed above) returns an iterator. I did similarly to you: I located the index of the value that mached the value returned by the Find iterator. String::find returns a position, which is what you were looking for, but sometimes one has to make do or locate some appropriate new thangy.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Mar 19th, 2006, 3:39 PM   #12
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 850
Rep Power: 4 The Dark is on a distinguished road
Note:
Quote:
cout << "You entered: ";
     while(nums[i] != '\0')
     {
          cout << nums[i] << " " ;
          i++;
     }
This loop may not stop where you want it to, nums[i] does not necessarily have a zero terminator at the end. It alos may have zero values in the middle. Stick with using the size() function to determine how many items there are.
The Dark is offline   Reply With Quote
Old Mar 20th, 2006, 12:57 AM   #13
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,221
Rep Power: 5 grumpy is on a distinguished road
If a and b are random access iterators, b-a is related to the number of elements between them. Not all containers support random access iterators, but some (eg std::vector) do. A pointer to elements in a contiguous array is a particular type of random access iterator......
grumpy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:10 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC