[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppString
To use them, the STL header file string.h must be #included.
Use string instead of an array of char [1,2,3].
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppString
(C++) std::string
STL container class for char. Or: 'the thing you use for storing words'.To use them, the STL header file string.h must be #included.
int main() { const std::string myString1 = "Hello"; const std::string myString2 = "World"; const std::string mySentence = myString1 + " " + myString2; std::cout << mySentence << std::endl; }
- include <iostream>
- include <string>
Use string instead of an array of char [1,2,3].
Handy functions
Common problems with strings
- Converting a std::string to an integer
- Converting a std::string to a double
- Converting an integer to a std::string
- Converting a double to a std::string
- Check if a std::string can be converted to an integer
- Check if a std::string can be converted to a double
- Convert a std::string to lower case
- Convert a std::string to upper case
- Finding a std::string in a std::string
- Get the path of a filename
- Get the extension of a filename
- Remove the extension of a filename
- Replace parts of a string by other strings
- Search a std::string in a std::string
- Seperate a std::string into multiple std::strings, seperated by a seperator
- Convert between std::string and AnsiString
Comparable data types
Topic links
- ::, scope operator
- <<, stream out operator
- #include
- char
- const
- cout
- endl
- #include
- int
- iostream(header file)
- main
- return
- scope operator, ::
- std
- std::cout
- std::endl
- stream out operator, <<
Reference
- 1) Bjarne Stroustrup. The C++ Programming Language (3rd edition).ISBN: 0-201-88954-4 Chapter 5.8.5: 'Use string rather then zero-terminated arrays of char'.
- 2) Herb Sutter and Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. ISBN: 0-32-111358-6. Chapter 77: 'Use vector and string instead of arrays.'
- 3) Scott Meyers. Effective STL. ISBN: 0-201-74962-9. Item 13: 'Prefer vector and string to dynamically allocated arrays'
- 4) Jarrod Hollingworth, Bob Swart, Mark Cashman, Paul Gustavson. Sams C++ Builder 6 Developer's Guide. ISBN: 0-672-32480-6. Chapter 3.1: 'Use a string class instead of char*'
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
