Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Type for string index

Reply
Thread Tools

Type for string index

 
 
Phil Endecott
Guest
Posts: n/a
 
      06-07-2005
Dear C++ Experts,

What type should I use for an index into a std::string? In the past I
have used an unsigned int, e.g.

unsigned int p = s.find("foo");
string t = s.substr(p,10);
etc. etc.

but I now find that this doesn't work on 64-bit machines; I get warnings
when I compare with npos saying that the comparison will always be false
due to the different ranges of the types.

My guess is that I should be using std::string::size_type. Is this right?

--Phil.
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      06-07-2005
Phil Endecott wrote:
> What type should I use for an index into a std::string? [...]
>
> My guess is that I should be using std::string::size_type. Is this right?


Yes.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index" camelean@shaw.ca ASP .Net 3 02-22-2011 07:06 PM
Program Index: cannot view entire index XP Luke O'Malley Computer Support 2 05-05-2008 03:34 AM
sorting index-15, index-9, index-110 "the human way"? Tomasz Chmielewski Perl Misc 4 03-04-2008 05:01 PM
index.htm or index.html ? Robert Cooze NZ Computing 15 12-13-2005 05:53 PM
problem with index.html .(page is automatically gettin redirected to index.html) karthikeyavenkat Java 2 03-17-2005 10:01 PM



Advertisments