#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;
#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();//让它显示停在那里,等待观察
}
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;
}