开发者社区> 问答> 正文

C++ 中的string类有哪些用法?

已解决

C++ 中的string类有哪些用法?

展开
收起
游客gzyuldo4mrg6i 2022-04-03 17:41:28 944 0
1 条回答
写回答
取消 提交回答
  • 推荐回答

    string类的字符操作:

    const char &operator[](int n)const; const char &at(int n)const; char &operator[](int n); char &at(int n);

    operator[]和at()均返回当前字符串中第n个字符的位置,但at函数提供范围检查,当越界时会抛出out_of_range异常,下标运算符[]不提供检查访问。

    const char *data()const;//返回一个非null终止的c字符数组 const char *c_str()const;//返回一个以null终止的c字符串

    int copy(char *s, int n, int pos = 0) const;//把当前串中以pos开始的n个字符拷贝到以s为起始位置的字符数组中,返回实际拷贝的数目

    2022-04-03 17:44:06
    赞同 展开评论 打赏
问答分类:
C++
问答地址:
问答排行榜
最热
最新

相关电子书

更多
使用C++11开发PHP7扩展 立即下载
GPON Class C++ SFP O;T Transce 立即下载
GPON Class C++ SFP OLT Transce 立即下载