C++中String类的截取字符串学习笔记

来源:互联网 发布:7u分享网络app 编辑:程序博客网 时间:2024/06/05 11:43

Java中截取字符串的方法有subString()的方法,可以方便的截取所需要的字符串,下面来学习下C++中截取字符串的方法。

#include <iostream>#include <string>#include <stdio.h>/* run this program using the console pauser or add your own getch, system("pause") or input loop */using namespace std; int main(int argc, char** argv) {string str="The current page will delete.";cout <<str.substr(2)<<endl;cout <<str.substr(str.find("c",0))<<endl;cin.get();return 0;}


头文件#include <stdio.h>是用来C语言打印日志的

substr截取字符串参数是开始截取字符串的小标索引

 

原创粉丝点击