c++ - 字符串名称和下标运算符前的 & 符号的含义
问题描述
最近我一直在玩 c++ 并注意到这段代码:
#include <iostream>
#include <string>
int main()
{
std::string word = "hello there";
std::cout << &word[2] << '\n';
}
打印变量词的后缀,即:“llo there”。
为什么会这样?它不应该返回第三个字符的地址吗?我还注意到这条线给出了相同的结果:
std::cout << &*(word.begin()+2) << '\n';
有人可以向我解释吗?预先感谢
解决方案
推荐阅读
- firebase - Xamarin.GooglePlayservices.Basement 与 netstandard2.0 不兼容
- c - 在指向 char 的指针数组中输入单词时出错
- javascript - 嵌套归约函数/递归/函数式编程/树遍历
- regex - 使用 nginx 阻止某些带有正则表达式的请求在位置不起作用
- angular - Angular 6:无法绑定到“上传者”
- bash - 如何将变量传递给bash中的命令
- sql-server - 将数据从 SQL Server 导入 SQLite?
- javascript - 试图获取随机数的值并将其放入特定的 div
- php - mysqli_query():空查询和未定义索引:abonent
- java - 如何使用辅助方法检查元音并在 Java 中返回字符串?