本文整理汇总了C++中std::basic_string::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ basic_string::resize方法的具体用法?C++ basic_string::resize怎么用?C++ basic_string::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::basic_string
的用法示例。
在下文中一共展示了basic_string::resize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TrimRight
void IO::TrimRight(std::basic_string<charType> & str, const char* chars2remove)
{
if (!str.empty()) { //trim the characters in chars2remove from the right
std::string::size_type pos = 0;
if (chars2remove != NULL) {
pos = str.find_last_not_of(chars2remove);
if (pos != std::string::npos)
str.erase(pos+1);
else
str.erase( str.begin() , str.end() ); // make empty
}
else { //trim space
pos = std::string::npos;
for (int i = str.size()-1; i >= 0; --i) {
if (!isspace(str[i])) {
pos = i;
break;
}
}
if (pos != std::string::npos) {
if (pos+1 != str.size())
str.resize(pos+1);
}
else {
str.clear();
}
}
}
}
示例2: read
int UsbIo::read( std::basic_string<unsigned char> & from ,int size )
{
if ( !isOpen() )
{
if ( !open() )
return -1;
}
from.resize( size );
/*
int res = libusb_control_transfer(
pd->handle,
CONTROL_REQUEST_TYPE_IN,
HID_GET_REPORT,
0, 0,
const_cast<unsigned char *>( from.data() ), from.size(), pd->timeout );
*/
int res = usb_control_msg( pd->handle, CONTROL_REQUEST_TYPE_IN,
HID_GET_REPORT,
0,
0,
(char *)( from.data() ),
from.size(),
pd->timeout );
if ( res < 0 )
{
close();
return res;
}
return res;
}
示例3: read
StorageSize read(std::istream& stream, std::basic_string<T>& value)
{
StorageSize size = read<StorageSize>(stream);
value.resize(size);
stream.read(&value[0], size * sizeof(T));
return size;
}
示例4: ar
//! Serialization for basic_string types, if binary data is supported
template<class Archive, class CharT, class Traits, class Alloc> inline
typename std::enable_if<traits::is_input_serializable<BinaryData<CharT>, Archive>(), void>::type
load(Archive & ar, std::basic_string<CharT, Traits, Alloc> & str)
{
size_t size;
ar( make_size_tag( size ) );
str.resize(size);
ar( binary_data( &(*str.begin()), size * sizeof(CharT) ) );
}
示例5: ar
//! Serialization for basic_string types, if binary data is supported
template<class Archive, class CharT, class Traits, class Alloc> inline
typename std::enable_if<traits::is_input_serializable<BinaryData<CharT>, Archive>::value, void>::type
CEREAL_LOAD_FUNCTION_NAME(Archive & ar, std::basic_string<CharT, Traits, Alloc> & str)
{
size_type size;
ar( make_size_tag( size ) );
str.resize(static_cast<std::size_t>(size));
ar( binary_data( const_cast<CharT *>( str.data() ), static_cast<std::size_t>(size) * sizeof(CharT) ) );
}
示例6: load
void load(std::basic_string<CharType> & s)
{
unsigned int l;
load(l);
s.resize(l);
// note breaking a rule here - could be a problem on some platform
if (l)
load_impl(const_cast<CharType *>(s.data()),
get_mpi_datatype(CharType()),l);
}
示例7: StringTrimRightT
void StringTrimRightT(std::basic_string<CharType> &output)
{
size_t length = output.length();
const CharType *src = output.data();
for (; length > 0; length--)
if (NOT_SPACE(src[length-1]))
break;
output.resize(length);
}
示例8: load
void load(std::basic_string<CharType> & s)
{
unsigned int l;
load(l);
// borland de-allocator fixup
#if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
if(NULL != s.data())
#endif
s.resize(l);
// note breaking a rule here - could be a problem on some platform
load_impl(const_cast<char *>(s.data()),l);
}
示例9: serialize
void serialize(input_archive & ar, std::basic_string<Char, CharTraits,
Allocator> & s, unsigned)
{
std::uint64_t size = 0;
ar >> size; //-V128
s.clear();
if (s.size() < size)
s.resize(size);
load_binary(ar, &s[0], size * sizeof(Char));
}
示例10: serialize
void serialize(input_archive & ar, std::basic_string<Char, CharTraits,
Allocator> & s, unsigned)
{
typedef std::basic_string<Char, CharTraits, Allocator> string_type;
typedef typename string_type::size_type size_type;
size_type size = 0;
ar >> size; //-V128
s.clear();
s.resize(size);
load_binary(ar, &s[0], size * sizeof(Char));
}
示例11: overflow
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = static_cast<int>(str_.size());
str_.push_back(static_cast<CharT>(__c));
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
示例12: overflow
virtual typename base::int_type
overflow(typename base::int_type ch = base::traits_type::eof())
{
if (ch != base::traits_type::eof())
{
std::size_t n = str_.size();
str_.push_back(static_cast<CharT>(ch));
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(static_cast<int>(n+1));
}
return ch;
}
示例13: serializeString
inline void serializeString(SF::Archive & ar, std::basic_string<C,T,A> & s)
{
if (ar.isRead())
{
boost::uint32_t count = 0;
ar & count;
SF::IStream &is = *ar.getIstream();
s.resize(0);
std::size_t minSerializedLength = sizeof(C);
if (ar.verifyAgainstArchiveSize(count*minSerializedLength))
{
if (count > s.capacity())
{
s.reserve(count);
}
}
boost::uint32_t charsRemaining = count;
const boost::uint32_t BufferSize = 512;
C buffer[BufferSize];
while (charsRemaining)
{
boost::uint32_t charsToRead = RCF_MIN(BufferSize, charsRemaining);
boost::uint32_t bytesToRead = charsToRead*sizeof(C);
RCF_VERIFY(
is.read( (char *) buffer, bytesToRead) == bytesToRead,
RCF::Exception(RCF::_SfError_ReadFailure()))
(bytesToRead)(BufferSize)(count);
s.append(buffer, charsToRead);
charsRemaining -= charsToRead;
}
}
else if (ar.isWrite())
{
boost::uint32_t count = static_cast<boost::uint32_t >(s.length());
ar & count;
ar.getOstream()->writeRaw(
(char *) s.c_str(),
count*sizeof(C));
}
}
示例14: TrimLeft
void IO::TrimLeft(std::basic_string<charType> & str, const char* chars2remove)
{
if (!str.empty()) //trim the characters in chars2remove from the left
{
std::string::size_type pos = 0;
if (chars2remove != NULL)
{
pos = str.find_first_not_of(chars2remove);
if (pos != std::string::npos)
str.erase(0,pos);
else
str.erase( str.begin() , str.end() ); // make empty
}
else //trim space
{
pos = std::string::npos; //pos = -1
for (size_t i = 0; i < str.size(); ++i)
{
if (!isspace(str[i]))
{
pos = i;
break;
}
}
if (pos != std::string::npos)
{
if (pos > 0)
{
size_t length = str.size() - pos;
for (size_t i = 0; i < length; ++i) str[i] = str[i+pos];
str.resize(length);
}
}
else
{
str.clear();
}
}
}
}
示例15: StringTrimT
void StringTrimT(std::basic_string<CharType> &output)
{
if (output.empty())
return;
size_t bound1 = 0;
size_t bound2 = output.length();
const CharType *src = output.data();
for (; bound2 > 0; bound2--)
if (NOT_SPACE(src[bound2-1]))
break;
for (; bound1 < bound2; bound1++)
if (NOT_SPACE(src[bound1]))
break;
if (bound1 < bound2) {
memmove((void *)src,
src + bound1,
sizeof(CharType) * (bound2 - bound1));
}
output.resize(bound2 - bound1);
}