GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::basic_string::operator[](3) C++ Standard Libary std::basic_string::operator[](3)

std::basic_string::operator[] - std::basic_string::operator[]


reference operator[]( size_type pos ); (until C++20)
constexpr reference operator[]( size_type pos ); (since C++20)
const_reference operator[]( size_type pos ) (1) (until C++20)
const; (2)
constexpr const_reference operator[]( size_type (since C++20)
pos ) const;


Returns a reference to the character at specified location pos. No bounds checking
is performed. If pos > size(), the behavior is undefined.


1) If pos == size(), the behavior is undefined.
2) If pos == size(), a reference to the character with value CharT() (until C++11)
(the null character) is returned.
If pos == size(), a reference to the character with value CharT() (the
null character) is returned.
(since C++11)
For the first (non-const) version, the behavior is undefined if this
character is modified to any value other than CharT() .


pos - position of the character to return


Reference to the requested character.


Constant.

// Run this code


#include <iostream>
#include <string>


int main()
{
std::string const e("Exemplar");
for (unsigned i = e.length() - 1; i != 0; i /= 2)
std::cout << e[i];
std::cout << '\n';


const char* c = &e[0];
std::cout << c << '\n'; // print as a C string


//Change the last character of s into a 'y'
std::string s("Exemplar ");
s[s.size()-1] = 'y'; // equivalent to s.back() = 'y';
std::cout << s << '\n';
}


rmx
Exemplar
Exemplary


at accesses the specified character with bounds checking
(public member function)
front accesses the first character
(C++11) (public member function)
back accesses the last character
(C++11) (public member function)
operator[] accesses the specified character
(C++17) (public member function of std::basic_string_view<CharT,Traits>)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.