string类中截断函数erase

来源:互联网 发布:软件是怎么设计的 编辑:程序博客网 时间:2024/05/02 02:29
// erase_str.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <string>#include <algorithm>#include <iostream>int main(){     using namespace std;  string strSample("Hello String! Wake up to a beautiful day!"); cout <<"The origin sample string is :" <<endl; cout <<strSample <<endl<<endl;  string::iterator iCharS = find( strSample.begin(),strSample.end(),'S' ); cout<<"Erasing character 'S' from the sample string :"<<endl; if( iCharS != strSample.end() ) {     strSample.erase(iCharS); } cout<<strSample<<endl<<endl; cout<<"Erasing a range between begin() and end() :"<<endl; strSample.erase(strSample.begin(),strSample.end());  if( strSample.length() == 0 ) {     cout<<"The string is empty"<<endl; }  getchar(); return 0;}


 

 

 

 

0 0