c++


How to easily convert an unsigned string to a string?


I define an unsigned string as a string containing unsigned chars:
namespace std
{
typedef basic_string<unsigned char> ustring;
}
Thus, given a basic std::string whose chars range from -128 to 127, how can I easily convert it to a std::ustring whose chars range from 0 to 255?
You may use the iterator constructor:
ustring to_ustring(const std::string& s)
{
return {s.begin(), s.end()};
}
You do:
using ustring = std::vector<unsigned char>;
std::string a("abc");
ustring b(a.begin(), a.end());
Note that the zero-terminator is not copied.
basic_string<unsigned char> would require specializing char_traits. And no new names can be added to namespace std.

Related Links

IDEA CLion 2016.2.1 can't recognize the function exit()
Audacity PCM Data [on hold]
Best practice to set up qt application that works for different DPI
openssl fips error on arm Linux
C++ - Pretty way to make frequencies add up to 1
integerset obtaining the given array
Arduino Invalid conversion from 'char' to 'char*'
virtual ClistCtrl with checkboxes on displayed report list style
Error when modifying vector member of another class
Interrupt Service Routine can't be called directly
Lambda capture by default reference vs named
convert bitset<64> to string every 8 bit
argument of type “int” incompatible with parameter of type “int”
When is the correct time to call restoreState for QHeaderView?
How does it pass lvalue reference to std::forward with CRTP?
Using lower_bound function in loop is giving runtime error?

Categories

HOME
hyper-v
objective-c
perl
loadrunner
slickgrid
highcharts
firmware
knn
unix
wildfly
fiware
caffe
boost
wayland
geogebra
cordova-plugins
datagrid
quandl
autofixture
amazon-sqs
bayesian
webassembly
restcomm
category
photon
drupal-modules
dht
laravel-blade
selenium-rc
cpu-registers
xmlstarlet
xfce
na
radius
maven-exec-plugin
street-address
easymock
angular-daterangepicker
rrd4j
angularjs-ng-model
libphonenumber
gear-vr
jedi-vim
live-connect-sdk
smartmeter
shodan
playstation
machinekey
leap-motion
sonarqube-4.5
cscore
svg-edit
mapfragment
virtual-directory
google-roads-api
simplify
zend-studio
idiorm
network-monitoring
jseparator
argo
offsetheight
approximation
protection
zipcode
determinants
pig-udf
curator
componentkit
ember-qunit
aglio
orca
sharepoint-clientobject
apiaxle
alassetslibrary
hiding
facebook-events
jsonexception
customvalidator
fatwire
sts-securitytokenservice
scalaquery
kiln
statusnet
tao
validationsummary
context-sensitive-help
asp.net-mvc-2-validation
mkstorekit
release-builds

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile