|
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'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() .
|
|
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 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....
|
|
How do you convert System::String to std::string in C++ .NET?
Answer Snippets (Read the full thread at stackoverflow):
StdString = toss(systemString); static std::string toss( System::String ^ s ) { // convert .NET System::String to std::string const char* cstr = (const char*) (....
There's a whole MSDN article on how to do this .
|
|
CString is quit handy, while std::string is more compatible with stl container. I am using hash_map, however, hash_map does not support CString as key, so I wish I could convert CString into std::string, is it possible?
Write a CString hash function seems...
Answer Snippets (Read the full thread at stackoverflow):
As std....
The code will fail for UNICODE builds.
According to CodeGuru :
'CString' to 'std::string':
CString cs("Hello"); std::string s((LPCTSTR)cs);
BUT: std::string cannot always construct from a LPCTSTR i.e.
|