Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the STL string limits?

Tags:

c++

string

What are the string limits for the Standard Template Library in C++?

like image 687
SomeUser Avatar asked Oct 05 '09 17:10

SomeUser


People also ask

Is there a size limit on STD string?

While an individual quoted string cannot be longer than 2048 bytes, a string literal of roughly 65535 bytes can be constructed by concatenating strings.

What is the capacity of string?

The capacity of a string reflects how much memory the string allocated to hold its contents. This value is measured in string characters, excluding the NULL terminator. For example, a string with capacity 8 could hold 8 characters. Returns the number of characters a string can hold without reallocation.

Is there a limit to the size of a string in C++?

There is no official limit on the size of a string. The software will ask your system for memory and, as long as it gets it, it will be able to add characters to your string.


1 Answers

#include <iostream>
#include <string>

int main() {
    std::cout << std::string().max_size() << std::endl;
    return 0;
}
like image 134
Alex B Avatar answered Sep 29 '22 10:09

Alex B