C++ 在字符串中插入子串+推断字符串是否由空格组成
#include "StdAfx.h" #include <string> #include <iostream> using namespace std; int main(void) { string str,str1,str2; int index; //推斷截取的子串是否由blanks組成 str=" cjc is a master."; str1="cjc is a master."; index=str.find("cjc"); str.assign(str.c_str(),index); if(str.find_first_not_of(" ")==-1) { cout<<"The string is constructed of blanks..."<<endl; } else { cout<<str<<endl; } //在字符串中插入子串 index=str1.find("master"); str2=str1.substr(index); str1.assign(str1.c_str(),index); str=str1+"good "+str2; cout<<str<<endl; system("pause"); return 0; }
轉載于:https://www.cnblogs.com/lytwajue/p/7363422.html
總結
以上是生活随笔為你收集整理的C++ 在字符串中插入子串+推断字符串是否由空格组成的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sigaction函数学习
- 下一篇: 解决远程连接mysql错误1130