C++:String Functions

From Progzoo

Revision as of 06:49, 21 November 2009 by Spoon! (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The methods and properties of the string type include:

string s="Andrew was here"
ExampleValueComment
s.length()14The number of characters
s == "another"falseTests for equality
s.substr(2,5)"drew"Characters from position 2, with a length of 5
s + " once""Andrew was here once"The strings are concatenated using +
s.find("was")6Returns string::npos if the substring is not there.