由于我未能编译以下程序,我想知道是否:
CharT* std::string::data();根据cppreference 的文档std::string::data(),从C++ 17开始,这个函数可以返回一个非const指针,指向作为字符存储的底层数组.
#include <string>
int main() {
std::string hello("world");
char* data = hello.data();
(void) data;
}
Run Code Online (Sandbox Code Playgroud)
g++ --version ; g++ -std=c++17 -O2 -Wall -Werror main.cpp
Run Code Online (Sandbox Code Playgroud)
g++ (GCC) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
main.cpp: In function 'int main()':
main.cpp:6:28: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
char* data = hello.data();
~~~~~~~~~~^~
Run Code Online (Sandbox Code Playgroud)
You*_*You 10
根据libstdc ++文档,您正在寻找的功能是在libstdc ++版本7中实现的.它被列为Give'std :: string'非const'.data ()'成员函数,提案P0272R1.
同样,libc ++文档列出了与libc ++版本3.9中实现的相同的提议.
| 归档时间: |
|
| 查看次数: |
210 次 |
| 最近记录: |