⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demo_string_class_2.cpp

📁 对于一个初涉VC++的人来书
💻 CPP
字号:

//****************************************************
// 注意: substr(m,n) 取本串由位置m开始的n个字符的子串
// 注意: 本串的起始位置为0
//****************************************************

# include <iostream>
# include <string>

using namespace std;

void main()
{

	string s1("Oh my god!");
	string s2=s1.substr(3,7);
	string s3=s1.substr(0,s1.length());
	string s4=s1.append(" How great!");

	cout<<"s1="<<s1<<endl;
	cout<<"s2="<<s2<<endl;
	cout<<"s3="<<s3<<endl;
	cout<<"s4="<<s4<<endl;

	cout<<s1.find('h')<<","<<s1.find('H')<<endl;
	cout<<s1.find("Oh")<<","<<s1.find("How")<<endl;

	return;
}

/*
s1=Oh my god! How great!
s2=my god!
s3=Oh my god!
s4=Oh my god! How great!
1,11
0,11
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -