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

📄 demo_string_class_1.cpp

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

//***************************************************
// 标准C++库中的字符串string类:
// 字符串构造函数、字符串操作成员函数、字符串运算符
//***************************************************

# include <iostream>
# include <string>

using namespace std ;

void trueFalse(int x)
{
	cout<<(x?"True":"False")<<endl;
}

void main()
{
	string S1="DEF", S2="123";
	char CP1[]="ABC"; 
	char CP2[]="DEF";

	cout<<"S1 is: "<<S1<<endl;
	cout<<"S2 is: "<<S2<<endl;
	cout<<"length of S2: "<<S2.length()<<endl;

	cout<<"CP1 is: "<<CP1<<endl;
	cout<<"CP2 is: "<<CP2<<endl;

	cout<<"S1<=CP1 returned: ";
	trueFalse(S1<=CP1); 

	cout<<"CP2<=S1 returned: ";
	trueFalse(CP2<=S1); 

	S2+=S1;
	cout<<"S2=S2+S1: "<<S2<<endl;
	cout<<"length of S2: "<<S2.length()<<endl;

	return;
}

/*
S1 is: DEF
S2 is: 123
length of S2: 3
CP1 is: ABC
CP2 is: DEF
S1<=CP1 returned: False
CP2<=S1 returned: True
S2=S2+S1: 123DEF
length of S2: 6
*/

⌨️ 快捷键说明

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