std::string is an STL container for storing char. Or: 'the thing you use for storing words'.
The definition of std::string is in string.h.
#include <iostream>
#include <string>
int main()
{
const std::string s1 = "Hello";
const std::string s2 = "World";
const std::string s3 = s1 + " " + s2;
std::cout << s3 << '\'n;
}
Prefer using std::string over an array of char [1][2][3][4].
std::string example
#include <cassert>
#include <string>
int main()
{
const std::string s = "ABCD";
assert(s.find("xx")==std::string::npos);
assert(s.find("BC")!=std::string::npos);
}
Note that among these are also the more general container code snippets.
- AnsiToStr, convert AnsiString to std::string
- Append two std::strings, Append
- Append, append two std::strings
- Ask user to input a double, AskUserForDouble
- Ask user to input a std::string, AskUserForString
- AskUserForDouble, ask user to input a double
- AskUserForString, ask user to input a std::string
- Check if std::string can be converted to double, IsDouble
- Check if std::string can be converted to integer, IsInt
- Convert AnsiString to std::string
- Convert double to std::string
- Convert integer to std::string
- Convert std::string to AnsiString
- Convert std::string to double
- Convert std::string to integer
- Convert std::string to lower case
- Convert std::string to upper case
- Convert std::string to WideString
- Convert WideString to std::string
- DoubleToStr, convert double to std::string
- Find std::string in std::string
- FindString, find std::string in std::string
- Get the extension of a filename
- Get the path of a filename, GetPath
- GetExtension, get the extension of a filename
- GetLongestString, find the length of the std::string with the most characters in a container
- GetPath, get the path of a filename
- GetShortestString, find the length of the std::string with the least characters in a container
- IntToStr, convert integer to std::string
- IsDouble, check if std::string can be converted to double
- IsInt, check if std::string can be converted to integer
- LoopReader, reading a container looped
- Reading a container looped, LoopReader
- Remove the extension of a filename
- Remove the path of a filename, RemovePath
- RemoveExtension, remove the extension of a filename
- RemovePath, remove the path of a filename
- Replace a substring by another in a certain std::string once, ReplaceOnce
- Replace all substrings by another in a certain std::string, ReplaceAll
- ReplaceAll, replace all substrings by another in a certain std::string
- ReplaceOnce, replace a substring by another in a certain std::string once
- ReverseString, reverse a std::string
- Reverse a std::string, ReverseString
- Seperate a std::string into multiple std::strings, seperated by a seperator
- SeperateString, seperate a std::string into multiple std::strings, seperated by a seperator
- SimplifyPath, simplify a path
- StrToAnsi, convert std::string to AnsiString
- StrToDouble, convert std::string to double
- StrToInt, convert std::string to integer
- StrToLower, convert std::string to lower case
- StrToUpper, convert std::string to upper case
- StrToWide, convert std::string to WideString
- SumStringLength, sum the lengths of std::strings irn a container
- Trim the leading and trailing spaces from a std::string
- Trim, trim the leading and trailing spaces from a std::string
- WideToStr, convert WideString to std::string
- Bjarne Stroustrup. The C++ Programming Language (3rd edition). 1997. ISBN: 0-201-88954-4. Chapter 5.8.5: 'Use string rather then zero-terminated arrays of char'.
- Herb Sutter, Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. 2005. ISBN: 0-32-111358-6. Chapter 77: 'Use vector and string instead of arrays'.
- Scott Meyers. Effective STL. ISBN: 0-201-74962-9. Item 13: 'Prefer vector and string to dynamically allocated arrays'
- 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*'