As per the documentation, these are just synonyms. size() is there to be consistent with other STL containers (like vector, map, etc.) and length() is to be consistent with most peoples’ intuitive notion of character strings. People usually talk about a word, sentence or paragraph’s length, not its size, so length() is there to make things more readable.
Related Posts:
- Parsing a comma-delimited std::string
- Remove spaces from std::string in C++
- Remove spaces from std::string in C++
- Which is faster C++ String length() or size()?
- How to do std::string indexof in C++ that returns index of matching string?
- Why the switch statement cannot be applied on strings?
- How to convert string to char array in C++?
- How can I convert a std::string to int?
- Easiest way to convert int to string in C++
- What is the easiest way to initialize a std::vector with hardcoded elements?
- std::string to char*
- How to convert string to char array in C++?
- C++ — expected primary-expression before ‘ ‘
- C++ string to double conversion
- Conversion from string to char – c++
- What is `CString`?
- How do I include the string header?
- Differences between C++ string == and compare()?
- How do I erase an element from std::vector<> by index?
- How to convert a char array to a string?
- How do I convert a double into a string in C++?
- Split a string using C++11
- Is it more efficient to copy a vector by reserving and copying, or by creating and swapping? [duplicate]
- How do I iterate over the words of a string?
- How to convert an instance of std::string to lower case
- Check if a string contains a string in C++
- How do I reverse a C++ vector?
- How do I iterate over the words of a string?
- Returning an empty string : efficient way in c++
- Replace part of a string with another string
- C++ string to double conversion
- A proper way to create a matrix in c++
- What is use of c_str function In c++
- How to reverse an std::string? [duplicate]
- C++ Parsing input string to variables
- std::string to char*
- How to convert a std::string to const char* or char*
- How do I tokenize a string in C++?
- Why use string::iterator rather than index?
- push_back vs emplace_back
- Why am I getting string does not name a type Error?
- C++ deprecated conversion from string constant to ‘char*’
- identifier “string” undefined?
- Press Enter to Continue
- Converting a vector
to string - How can I convert const char* to string and then back to char*?
- std::string formatting like sprintf
- Sorting Characters Of A C++ String
- basic_string::_M_construct null not valid after constructing subvector of strings
- How to copy a string of std::string type in C++?
- How to ensure that a std::map is ordered?
- How to return a string from a C++ function?
- std::out_of_range error?
- What is the difference between isdigit() and isnumber()?
- Convert char* to string C++
- printf with std::string?
- Convert a String In C++ To Upper Case
- Right way to split an std::string into a vector
- Read whole ASCII file into C++ std::string
- C++: std does not have member “string”
- Right way to split an std::string into a vector
- string subscript out of range error
- C++ String Variable Declaration
- push_back vs emplace_back
- Returning an empty string : efficient way in c++
- Split a string into an array in C++
- splitting a string into an array in C++ without using vector
- What is the difference between const_iterator and non-const iterator in the C++ STL?
- How to check that an element is in a std::set?
- What’s the most efficient way to erase duplicates and sort a vector?
- c++ convert string to hex
- Best way to extract a subvector from a vector?
- How can I iterate through a string and also know the index (current position)?
- c++ parse int from string [duplicate]
- Appending a vector to a vector
- Hash function for a string
- Determine if map contains a value for a key?
- C++ strings and pointers
- How to Convert a C++ String to Uppercase
- std::wstring VS std::string
- C++ Simple hangman game
- std::cin input with spaces?
- Remove First and Last Character C++
- C++ Remove punctuation from String
- C++ Erase vector element by value rather than by position?
- C++ string to enum
- C++ Convert string (or char*) to wstring (or wchar_t*)
- C++ – Assigning null to a std::string
- How to alphabetically sort strings?
- How to get current time in milliseconds?
- Hash function for a string
- Reading string by char till end of line C/C++
- How do I check if a C++ std::string starts with a certain string, and convert a substring to an int?
- Dynamically allocated string array, then change it’s value?
- Use the auto keyword in C++ STL
- Fastest way to Convert String to Binary?
- Why I cannot cout a string?
- How to print a string in C++
- How to convert QString to int?
- How do I create a random alpha-numeric string in C++?