string::front

char& front();
const char& front() const;
功能:返回string对象的首个字符,可以改变它的值

#include <string>
#include <iostream>

using namespace std;

int main()
{
string s1("test");
cout << s1.front() << endl;
s1.front() = 'T';
cout << s1 << endl;
string s2;
cout << s2.front() << endl;
}

posted @ 2019-12-24 23:33  MoonXu  阅读(354)  评论(0编辑  收藏  举报