zoukankan      html  css  js  c++  java
  • string.clear()

    string.clear() - liuyy的专栏 - 博客频道 - CSDN.NET

    string.clear()

    分类: 关于C++ 1236人阅读 评论(0) 收藏 举报

         今天看了一段的代码。发现好多的东西平时都没有用过。

    我们来看看这个吧,是string中的一些函数。它存在C++ library内.

    <string>被包含进来,在其中的Classes内的Member Functions中basic_string::clear

    就是它了。

    basic_string::clear

              Erases all elements of a string.

    void clear( );
    备注(remarks):The string on which the member function is called will be empty.
    相关的例子如下(不是我写的哦~):
    // basic_string_clear.cpp
    // compile with: /EHsc
    #include <string>
    #include <iostream>
    
    int main( )
    {
       using namespace std;
       string  str1 ("Hello world"), str2;
       basic_string <char>::iterator str_Iter;
       cout << "The original string str1 is: ";
       for ( str_Iter = str1.begin( ); str_Iter != str1.end( ); str_Iter++ )
          cout << *str_Iter;
       cout << endl;
    
       str1.clear ( );
       cout << "The modified string str1 is: ";
       for ( str_Iter = str1.begin( ); str_Iter != str1.end( ); str_Iter++ )
          cout << *str_Iter;
       cout << endl;
    
       //For an empty string, begin is equivalent to end
       if ( str1.begin ( ) == str1.end ( ) )
          cout << "Nothing printed above because "
               << "the string str1 is empty." << endl;
       else
          cout << "The string str1 is not empty." << endl;
    }
    结果呢(output):
    The original string str1 is: Hello world
    The modified string str1 is: 
    Nothing printed above because the string str1 is empty.

    应该看得懂了吧~

  • 相关阅读:
    css概述五
    css概述四
    css概述三
    css概述二
    css概述
    Python的第三方web开发框架Django
    Python中的模块和包
    SQL语句优化
    数据库向Excel写入数据
    动态拼接sql语句
  • 原文地址:https://www.cnblogs.com/lexus/p/2771958.html
Copyright © 2011-2022 走看看