订阅字符串文字

Nik*_*iou 3 c++

订阅字母数字是一种常见/有效的技术吗?什么是隐含的转换?例如:

#include <iostream>
using namespace std;

int main() 
{
    int k(2);
    cout << "Hello"[k] << endl;
    cout << (k-1)["Hello"] << endl;
    // your code goes here
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Che*_*Alf 8

索引文字字符串并不常见,但它有其用途,例如

auto hex_digit( int const value )
    -> char
{
    assert( 0 < value && value < 0x10 );
    return "0123456789ABCDEF"[value];
}
Run Code Online (Sandbox Code Playgroud)