std::basic_string::front
来自cppreference.com
                    
                                        
                    < cpp | string | basic string
                    
                                                            
                    |   CharT& front();  | 
(C++11 起) | |
|   const CharT& front() const;  | 
(C++11 起) | |
返回到 string 中首字符的引用。若 empty() == true 则行为未定义。
目录 | 
[编辑] 参数
(无)
[编辑] 返回值
到首字符的引用,等价于 operator[](0) 。
[编辑] 复杂度
常数
[编辑] 示例
运行此代码
#include <iostream> #include <string> int main() { { std::string s("Exemplary"); char& f = s.front(); f = 'e'; std::cout << s << '\n'; // "exemplary" } { std::string const c("Exemplary"); char const& f = c.front(); std::cout << &f << '\n'; // "Exemplary" } }
输出:
exemplary Exemplary
[编辑] 参阅
|    (C++11)  | 
  访问最后的字符  (公开成员函数)  |