Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
static const string FindSentinel() { return "<Dummy>"; }
static const string Void() { return "<Null>"; }
What does this do, and how can these functions be used?
Is "<Dummy>" and "<Null>" a keyword?
No. They are plain string literals.
The calling code may assign special meaning to those strings (if it wants to), but as far as the C++ language is concerned, they are just any old run-of-the-mill string literal - nothing to see here, move along.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am looking for a function to compare the two strings. A functional similar to strcmp in CString with the difference that takes two strands in the input.
You can use std::string::compare (it returns 0 if values are the same). Also be aware that in fact you can use strcmp in c++, but if you want modern c++ version i would go with std::string::compare.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I always wondered why one can't just convert null-terminated C string into std::string(without constructors, writing helper functions and other workarounds)? It appears to be a simple and overly commonplace problem, where you have, let's say argv[1] null-terminated string as an argument passed to your program(or any other naturally occurred C string) and you need to pass it's value to a function directly.
I.e
How do I wrap the cstr in-place without allocating new string object?
This is the answer as best I can tell.
const char * cstr = "Hello World.";
...
..myfunc(cstr);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am having problems in understanding this statement. I don't know why this is not usual like others.
Assignment means giving a new value to an already existing object. Even though const char INITIAL='G'; has an = sign, it is not an assignment, because it is creating a new object, not modifying an existing one. char INITIAL; INITIAL='G'; would be an assignment, because INITIAL already exists when the new value is, well, assigned.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I've tried searching for the answer, but nothing mentions stringstream specifically. I would guess that it would always work and you can always go back as far as the beginning of the underlying string.
Am I right?
How likely is istream::ungetc() to work with a stringbuf (as used in stringstream)?
Well, never.
There's no such thing like istream::ungetc() defined from the standard.
You can use either
int std::ungetc( int ch, std::FILE *stream )
or
std::basic_istream& std::basic_istream::unget()
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
All my attempts so far have failed.Basically when I return a copy of the internal char array of the string, that copy has to be released, but I don't know how to release it.Wrapping it in a smart pointer doesn't work out, since it's destructor gets called immediately after I return it.Must I implement something like a garbage collector just for the immutable string?
const std::string will be fine.