By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,900 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,900 IT Pros & Developers. It's quick & easy.

Type for string index

P: n/a
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.
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.