Linked Questions

138 votes
6 answers
130k views

Will the below string contain the null terminator '\0'? std::string temp = "hello whats up";
mister's user avatar
  • 3,483
73 votes
4 answers
10k views

In C++11 basic_string::c_str is defined to be exactly the same as basic_string::data, which is in turn defined to be exactly the same as *(begin() + n) and *(&*begin() + n) (when 0 <= n < ...
Mankarse's user avatar
  • 40.9k
9 votes
3 answers
3k views

We all know there is a null character automatically attached to the end of a C-string. What about a std::string object? Is there also a null character at the end of it?
user1050165's user avatar
1 vote
2 answers
2k views

It is possible to call .c_str() for a C++ const string. In order to efficiently implement this, it means that it must internally store an extra null character. (Otherwise, copying or modifying data ...
CaptainCodeman's user avatar
5 votes
3 answers
648 views

Some excerpts from the standard first: Spec for string::operator[](): const_reference operator[](size_type pos) const; reference operator[](size_type pos); Requires: pos <= size(). Returns:...
goodbyeera's user avatar
  • 3,199
0 votes
0 answers
67 views

#include <iostream> #include <string> #include <cstring> int main() { using namespace std; string cppString = "string1"; //size of C++ String cout << sizeof(...
lostsoul's user avatar
38 votes
6 answers
6k views

What are the problems of a zero-terminated string that length-prefixed strings overcome? I was reading the book Write Great Code vol. 1 and I had that question in mind.
user avatar
53 votes
4 answers
29k views

For regular C strings, a null character '\0' signifies the end of data. What about std::string, can I have a string with embedded null characters?
WilliamKF's user avatar
  • 43.6k
26 votes
3 answers
2k views

In the C++ reference of c_str() in std::string the following appears: Return value Pointer to the underlying character storage. data()[i] == operator[](i) for every i in [0, size()) (until C++11)...
Chiel's user avatar
  • 6,204
10 votes
4 answers
29k views

I am brushing up on my C++ and stumbled across a curious behavior in regards to strings, character arrays, and the null character ('\0'). The following code: #include <iostream> using namespace ...
ewok's user avatar
  • 21.7k
10 votes
3 answers
6k views

What is the internal structure of std::wstring? Does it include the length? Is it null terminated? Both?
Jonathan Allen's user avatar
3 votes
7 answers
3k views

std::string.c_str() returns a (const char *) value. I Googled and found that I can do the following: std::string myString = "Hello World"; char *buf = &myString[0]; How is this possible? &...
user1365914's user avatar
5 votes
1 answer
10k views

I'm using VS2012/C++, I need to convert a std::string to char * and I can't find any material online giving any guidance on how to go about doing it. Any code examples and advice will be greatly ...
Ryan's user avatar
  • 985
2 votes
6 answers
6k views

I have given a byte array [97, 98, 0, 99, 100] which is GSM 7-Bit encoded. This should be converted into ab@cd. When I tried to append this given array into a StringBuilder, I was not able to convert ...
Haim Klainman's user avatar
7 votes
2 answers
6k views

One thing I'm not pretty sure after googling for a while, is the returned string of getline(). Hope to get it confirmed here. std::getline This global version returns a std::string so it's not ...
Eric Z's user avatar
  • 14.7k

15 30 50 per page