本文整理汇总了C++中std::basic_string::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ basic_string::insert方法的具体用法?C++ basic_string::insert怎么用?C++ basic_string::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::basic_string
的用法示例。
在下文中一共展示了basic_string::insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: move
std::basic_string < Elem, Traits > cell_encode(std::basic_string < Elem, Traits > Str, Elem Sep_, Elem Esc){
if(Str.find(Sep_) < Str.size() || Str.find(Esc) < Str.size()){
for(auto itr = Str.begin(); itr != Str.end(); ++itr){
if(*itr == Esc){
itr = Str.insert(++itr, Esc);
}
}
Str.insert(Str.begin(), Esc);
Str.push_back(Esc);
}
return std::move(Str);
}
示例2: edit_loop
bool FeOverlay::edit_loop( std::vector<sf::Drawable *> d,
std::basic_string<sf::Uint32> &str, FeTextPrimative *tp )
{
const sf::Transform &t = m_fePresent.get_transform();
const sf::Font *font = tp->getFont();
sf::Text cursor( "_", *font, tp->getCharacterSize() );
cursor.setColor( tp->getColor() );
cursor.setStyle( sf::Text::Bold );
cursor.setScale( tp->getTextScale() );
int cursor_pos=str.size();
cursor.setPosition( tp->setString( str, cursor_pos ) );
bool redraw=true;
FeKeyRepeat key_repeat_enabler( m_wnd );
while ( m_wnd.isOpen() )
{
sf::Event ev;
while (m_wnd.pollEvent(ev))
{
switch ( ev.type )
{
case sf::Event::Closed:
return false;
case sf::Event::TextEntered:
switch ( ev.text.unicode )
{
case 8: // Backspace
if ( cursor_pos > 0 )
{
str.erase( cursor_pos - 1, 1 );
cursor_pos--;
}
redraw = true;
break;
case 9: // horizontal tab
case 10: // linefeed
case 13: // Return (ignore here, deal with as keypress event)
break;
case 127: // Delete
if ( cursor_pos < (int)str.size() )
str.erase( cursor_pos, 1 );
redraw = true;
break;
default: // General text entry
if ( cursor_pos < (int)str.size() )
str.insert( cursor_pos, 1, ev.text.unicode );
else
str += ev.text.unicode;
cursor_pos++;
redraw = true;
}
break;
case sf::Event::KeyPressed:
switch ( ev.key.code )
{
case sf::Keyboard::Left:
if ( cursor_pos > 0 )
cursor_pos--;
redraw = true;
break;
case sf::Keyboard::Right:
if ( cursor_pos < (int)str.size() )
cursor_pos++;
redraw = true;
break;
case sf::Keyboard::Return:
return true;
case sf::Keyboard::Escape:
return false;
default:
break;
}
default:
break;
}
if ( redraw )
cursor.setPosition( tp->setString( str, cursor_pos ) );
}
if ( m_fePresent.tick( NULL ) )
redraw = true;
//.........这里部分代码省略.........