C++:关于string转C-风格字符串
2015-04-15 20:47
483 查看
std::basic_string::c_str
C++
Strings library
std::basic_string
const CharT* c_str() const; | ||
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/C++关于字符串string、char*字符串数组与其他类型转换
- [C++/STL] string字符串关于copy函数的C4996错误
- [C++/STL] string字符串关于copy函数的C4996错误
- C++ 中string类型和 C风格 char类型字符串比较
- 【C++】【日志贴】浅谈标准库类型string、vector及C风格字符串在全局和局部作用域中默认初始值情况
- C风格字符串和C++的标准库类型string的比较
- c风格字符串和C++的string在文件名方面的使用注意
- MFC中CString,C++中string,c风格字符串
- 有关于String字符串的坑(==号和equals的区别)
- c++ 关于字符串处理函数的整理
- [C/C++标准库]_[初级]_[使用模板删除字符串前后空格((w)string space)]
- c++的字符串string处理
- C++中字符串string和整数int的互相转化方式
- C风格字符串与string类型(整理)
- c++复习笔记(字符串string)
- C++ 标准头文件与C头文件区别与联系以及C风格字符串
- 关于c++字符串的 sort排序(字典序)
- 关于字符串string的知识记录 = = 防忘
- C++字符串:string and wstring的区别,非常重要!!!!
- C/C++中关于字符串数组与字符串常量