string与vector

#include <iostream>
#include <cctype>
#include <string>
#include <vector>
using namespace std;

int main1()
{
string  s("do something string");//直接初始化一个string字符串
if (!s.empty())
{
s[0] = toupper(s[0]);//将首字母(使用下标)转换大写
}


cout << s << endl;//若未加第三行的包含语句。此语句不能编译通过。原因在于重载string类 <<  的 操作符 


cout << " Is  s.size : " << s.size() << endl;  //a 的大小输出


for (decltype(s.size()) index = 0; index != s.size() && !isspace(s[index]); ++index)
{
s[index] = toupper(s[index]);
}

cout << "This is new s : " << s << endl;

getchar();//让它显示停在那里,等待观察


return 0;

}

int main()
{
string  num1[] = { "one", "two", "three" };
string *p = &num1[0];//num1 的元素分别为 one  two three   , p指向num1 的首元素
cout << *p << endl;//输出 one


//以下内容 用整形数组 初始化 vector 对象
//start
int a[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
vector <int> v1(begin(a), end(a));//v1  里面将有8个元素  与a 一致
cout << v1[1] << endl;//2
//end
getchar();
return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Teleger

你的支持是我前进的方向

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值