我是靠谱客的博主 单纯翅膀,最近开发中收集的这篇文章主要介绍C++:关于string转C-风格字符串 std::basic_string::c_str,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
std::basic_string::c_str
const CharT* c_str() const;
| ||
Returns a pointer to a null-terminated character array with data equivalent to those stored in the string.
The pointer is such that the range [c_str(); c_str() + size()]
is valid and the values in it correspond to the values stored in the string with an additional null character after the last position.
The pointer obtained from c_str()
may be invalidated by:
- Passing a non-const reference to the string to any standard library function, or
- Calling non-const member functions on the string, excluding operator[], at(), front(), back(), begin(),rbegin(), end() and rend().
Writing to the character array accessed through c_str()
is undefined behavior.
c_str() and data() perform the same function. | (since C++11) |
这里:
用c_str() 方法可以返回一个指向C-风格的字符串的指针。
如:
string filename;
cout << "Enter the file name: ":
cin >> filename;
ofstream fout;
fout.open(filename.c_str());
最后
以上就是单纯翅膀为你收集整理的C++:关于string转C-风格字符串 std::basic_string::c_str的全部内容,希望文章能够帮你解决C++:关于string转C-风格字符串 std::basic_string::c_str所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复