How many characters does string class in c++ support? [duplicate] - c++

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Maximum length of a std::basic_string<_CharT> string
I would like to know how many characters does string class in c++ support.
thanks..

std::string s;
s.max_size();
That should tell you what that max size is.

according to http://www.idinews.com/string3.html
The std::string class supports varying length strings with no length limit.

I am lead to believe that the size of a std::string object is limited to size of an unsigned integer on the architecture of your system. I would assume this since the length of the string is stored as a size_t value.

Related

C++ string length [duplicate]

This question already has answers here:
What does the C++ standard state the size of int, long type to be?
(24 answers)
Getting the actual length of a UTF-8 encoded std::string?
(11 answers)
Closed 2 years ago.
I was reading the documentation of string::length and, as you can see, it says that
Returns the length of the string, in terms of bytes.
So my question is, is this ensured to be also the number of char that it contains?
I know that usually a char is 1 byte, but is this ensured somewhere? Like in the standard or somewhere else?

What is the best way to convert a string type to an int type as Industry standard? [duplicate]

This question already has answers here:
How to parse a string to an int in C++?
(17 answers)
Closed 6 years ago.
In C++, what is the best way to take input string and convert it to a number type. I was messing around with literal strings and was having a difficult time doing this, I am imagining that using a C String is easier? What is the best way for co-workers and fellow students to follow and make it easy and simple? Any thoughts?
What is the industry standard on this? Using STOI?
Look at the following example:
std::string numberString = "125";
int number = std::stoi(numberString ,nullptr);
It can convert an std::string to int

C++ strings vs vector<char> [duplicate]

This question already has answers here:
What are differences between std::string and std::vector<char>?
(5 answers)
C++: char test[100] vs array<char, 100> vs string
(4 answers)
Closed 7 years ago.
It's known to everyone of us that we should prefer string class in C++ for all string applications due to the many special functions they perform & their ability to grow & reduce dynamically. What string is for characters, vector is for other data types & classes because it shows great performance.
However is there any situation where we would need to prefer vector<char> (which I see seldom) over string ?
I'd use vector<char> only if I explicitly intent to store an array of char values, which is not a string. E.g. if for some reason I'd collect all the characters used somewhere in a specific text, the result might be a vector<char>.
To be clear: it is all about expressing the intent.
To put it briefly: if you're storing text, then string, otherwise vector<char>.

How to convert a double into a char* [duplicate]

This question already has answers here:
Converting double to char* in C++ with high performance
(9 answers)
Closed 7 years ago.
I am heavily struggling with a question which should be very easy: how do I do a simple type conversion (from double into char*) in basic C.
I have found quite some solutions, but they are all based on conversions from double to char[x], but I am working here with char*, not with char[]. (I don't know how long the resulting string will be).
On top of that, I really can't believe that another type (be it stringstream, std::strings, ...) are needed for something that simple.
I admit, I'm a complete newbie in basic C, but I have worked in other languages (Visual Basic, Delphi, Java, ...) and I just can't understand why I can't find a simple function like "to_char_pointer(double d)" to do this.
Does anybody have an idea?
You can use sprintf() as you have done to convert a double to a string, but I would actually recommend using _snprintf() instead simply because sprintf() has no regard for the fact that strings are fixed length devices in memory and will overflow if you don't watch it. _snprintf() allows you to specify the length of the out string, just be sure to specify the size as one less than the actual allocated memory block, because _snprintf() does not store the terminating null character if it has to cut the output short.
An example us using _snprintf() is:
void ToString(char * outStr, int length, double val)
{
_snprintf(outStr,length,"%f",val);
}

Input of integer in the range of 10^1000 [duplicate]

This question already has answers here:
Handling large numbers in C++?
(10 answers)
Closed 8 years ago.
Is it possible to take an input of range greater than what C/C++ provides? Is it possible to accept an input range greater than that of unsigned long long and even larger up to the range of 10^1000?
If it is possible in C/C++, please answer how it can be done, thanks.
There's no bigint in C or C++, however library like this one can provide it: https://code.google.com/p/infint/
Input into a string. Then convert the string into the desired type.
If you use a library that provides types for large integers, such a library might also offer input functions.