string多种用法

这篇博客介绍了C++编程中string类型的基本用法,包括如何声明和使用string变量,结合示例展示了其在实际编程中的应用。
摘要由CSDN通过智能技术生成

#include
#include <windows.h>
#include

using namespace std;

int main(void) {
string like; //喜欢

cout << "你喜欢干什么:" << endl;
cin >> like;
cout << "喜欢" << like << "那就努力吧!" << endl;


string  The_answer; //这问题答案
string  reason;     //理由

cout << "你想做什么:" << endl;
cout << "为什么:" << endl;
cin >> The_answer >> reason;


string  hobby;   //爱好
int     i = 0;   

cout << "你有啥爱好?";
while (cin >> hobby) {
	i = i+1;
	if (i == 2) {
		break;
	}
	cout << "你的第 " << i << "爱好是:" << hobby << endl;
	cout << "你还有啥爱好?" << endl;
	
}


string read;  //读取

cout << "请输入一句话:" << endl;
getline(cin, read);
getline(cin, read);

if (read.empty() ==
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值