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 take lots of time.
CString ------> std::string ? how can I do?
std::string -----...
I'm using std::string and need to left pad them to a given width. What is the recommended way to do this in C++?
Sample input:
123
pad to 10 characters.
Sample output:
123
(7 spaces, prior to 123)
...
int main(void)
{
std::string foo("foo");
}
My understanding is that the above code uses the default allocator to call new. So even though the std::string foo is allocated on the stack the internal buffer inside of foo is allocated on the heap.
How can I create a string that is allocated entirely on the stack?
...
When I use std::string and when char* to manage arrays of chars in C++?
It seems you should use char* if performance(speed) is crucial and you're willing to accept some of a risky business because of the memory management.
Are there other scenarios to consider?
...
I have following code:
Tools::Logger.Log(string(GetLastError()), Error);
GetLastError() returns a DWORD a numeric value, but the constructor of std::string doesnt accept a DWORD.
What can I do?
thanks in advance
...
How to force std::stringstream operator >> to read an entire string instead of stopping at the first whitespace?
I've got a template class that stores a value read from a text file:
template <typename T>
class ValueContainer
{
protected:
T m_value;
public:
/* ... */
virtual void fromString(std::string & str)
{
std::strings...
I need to use std::string to store data retrieved by fgets(). To do this I need to convert fgets() char* output into an std::string to store in an array. How can this be done?
...
I have the following string:
index 0 1 2 3 4 5 6 7
std::string myString with the content of "\xff\xff\xff\x00\xff\x0d\x0a\xf5"
When I'm refering to myString[3], I get the expected '\x00' value.
But when I'm referring to myString[5], I get two values "\x0d\x0a" instead of just '\x0d'...
The situation:
I have a std::vector that contains strings at specific offsets. Here's a shortened dump:
...
@128 00 00 00 00 00 00 00 00 73 6F 6D 65 74 68 69 33 ........somethin
@144 38 36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ng..............
@160 00 00 00 00 00 00 00 00 31 2E 32 2E 33 00 00 00 ........1.2.3...
@176 00...
As a learning exercise, I have been looking at how automatic type conversion works in C++. I know that automatic type conversion should generally be avoided, but I'd like to increase my knowledge of C++ by understanding how it works anyway.
I have created a StdStringConverter class that can be automatically converted to a std::string, ...
I have an std::string containing a command to be executed with execv, what is the best "C++" way to convert it to the "char *argv[]" that is required by the second parameter of execv()?
To clarify:
std::string cmd = "mycommand arg1 arg2";
char *cmd_argv[];
StrToArgv(cmd, cmd_argv); // how do I write this function?
execv(cmd_argv[0], ...
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...
...
Dear All,
I have the following problem. I am trying to integrate a large code written by me with a QT interface. Some of my functions return std::string; I did not succeed in making setText accept them (other functions returning char do not give me problems).
What should I do? Thanks!
Giuseppe
...
I'm trying to compile the following code in C++
string initialDecision ()
{
char decisionReviewUpdate;
cout << "Welcome. Type R to review, then press enter." << endl;
cin >> decisionReviewUpdate;
// Processing code
}
int main()
{
string initialDecision;
initialDecision=initialDecision();
//ERROR OCCURS HERE
// Mor...
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_type(-1) (yes i know I'm assuming 2's complement, but that's unrelated to the actual quest...
Is there anyway to read a known number of bytes, directly into an std::string, without creating a temporary buffer to do so?
eg currently I can do it by
boost::uint16_t len;
is.read((char*)&len, 2);
char *tmpStr = new char[len];
is.read(tmpStr, len);
std::string str(tmpStr, len);
delete[] tmpStr;
...
Is there an string equivalent to LPTSTR? I know of string and wstring. Is there a tstring?
...
class mystring {
private:
string s;
public:
mystring(string ss) {
cout << "mystring : mystring() : " + s <<endl;
s = ss;
}
/*! mystring& operator=(const string ss) {
cout << "mystring : mystring& operator=(string) : " + s <<endl;
s = ss;
//! return this;
return (mystring&)this; // why COMPILE ERROR
} */
mystring o...
I'm doing some maintenance work and ran across something like the following:
std::string s;
s.resize( strLength );
// strLength is a size_t with the length of a C string in it.
memcpy( &s[0], str, strLength );
I know using &s[0] would be safe if it was a std::vector, but is this a safe use of std::string?
...
I have a class which returns a typed pointer to a "const TCHAR". I need to convert it to a std::string but I have not found a way to make this happen.
Can anyone provide some insight on how to convert it?
...