|
What's the difference between std::string and std::basic_string ? And why are both needed?
Started by Benj on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
std::string is an instantiation of std::basic_string: typedef std....
std::basic_string is a class template for making strings out of character types, std::string required by the standard).
|
|
Why would I ever want to call std::string::data() over std::string::c_str() ? Surely there is some method to the standard's madness here...
Started by fbrereto on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Use c_str() if the code you are using assumes a string is NUL.
Data() returns a pointer to the data without any modifications .
With a NUL byte appended so you can use the return value as a "C string".
|
|
How can operator bool() cause an error when declaring operator std::string in a class and also serving as an implicit conversion to string by itself?
#include <iostream> #include <string> using namespace std; class Test { public: operator ...
Started by piotr on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
The problem you are facing (besides operator std::string() returning a bool) is that implicit conversions trigger when you want= matches:
// using ....
Your operator std::string() needs to return a string, not a bool.
|
Ask your Facebook Friends
|
I keep receiving a C2664 conversion error in visual studio
It tells me that it can't convert parameter 1 from const std::string to std::string&. I tried adding/removing the const in the stringToWstring prototype and in the function itself and the error...
Started by styx777 on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Since you want to use std::_String_const_iterator<_Elem,_Traits,_Alloc> in the error message from the second const stdI think the tokenizer iterator....
Three template arguments, and the third one defaults to std::string .
|
|
Recently I've noticed that the following statement is not true given std::string s .
s.max_size() == s.get_allocator().max_size();
I find this interesting, by default std::string will use std::allocator<char> which has a theoretical limit of size...
Started by Evan Teran on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
And after all std::basic_string is a container standard to store the string in ....
I am not entirely sure but as far as I know std::basic_string is not limited in the current it seems to be the case with STL containers.
|
|
I have a bunch of strings that I need to sort. I think a std::vector would be the easiest way to do this. However, I've never used vectors before and so would like some help.
I just need to sort them alphanumerically, nothing special. Indeed, the string...
Started by samoz on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
So * is needed c_str() is afaik a function of std::string and not a variable The problems in your
In particular, std::string::compare couldn't be used as a comparator, because it doesn't do what sort::string makes ....
|
|
I'm being stupid here but I can't get the function signature for the predicate going to find_if when iterating over a string:
bool func( char ); std::string str; std::find_if( str.begin(), str.end(), func ) )
In this instance google has not been my friend...
Started by Patrick on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
And, actually, you ....
) { return c == 'x'; } int main() { std::string str ="abcxyz";; std::string::iterator it = std::find::string str you can probably use std::find() rather than std::find_if() .
|
|
This may seem to be an academic question, but still I would be very interested in the answer:
I have a vector of strings s in which I would like to find a given string findme . This can be done using something like
find(s.begin(), s.end(), findme);
My...
Started by fuenfundachtzig on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Another thing you are forgetting is that std::string::compare returns 0 for equal(), std::not1(....
std::equal_to<string>(), string("findme")));
One option is to cast the member function pointer to suitable type.
|
|
Can someone please post a simple code that would convert
System::String^
to
C++ std::string
?
i.e I just want to assign the value of
String^ originalString;
to
std::string newString;
Started by ShaChris23 on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Void StringToStlWString ( System::String const^ s, std::wstring& os) { String^ string = const_cast<::String^ StlWStringToString (std::wstring const& os) { String^ str = gcnew String(os.c_str(....
|
|
I know that the individual map queries take a maximum of log(N) time. However I was wondering, I have seen a lot of examples that use strings as map keys. What is the performance cost of associating a std::string as a key to a map instead of an int for...
Started by Mr.Gando on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
To be something like this (untested):
class Key { public: unsigned hash; std::string s; int cmp(const Key mentioned, a string key will also cause an additional memory allocation each time an item is added as the length of string....
|