怎样算string的长度?用那个函数?

pijiupaopao 2005-04-29 04:13:49
如题
...全文
314 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
pijiupaopao 2005-04-29
  • 打赏
  • 举报
回复
在问个问题。
怎么样把string形转换为int形。
如:string str="123ad";----------->int n=0X123ad;(用那个函数转换?)
pijiupaopao 2005-04-29
  • 打赏
  • 举报
回复
看来是我意思没表达清楚,只有useresu(俗人)懂了,呵呵,谢谢大家!
Cnwanglin 2005-04-29
  • 打赏
  • 举报
回复
#include <cstring>
//if the complier can't find the cstring, please use #include <string>
#include <iostream>
using namespace std;

//And then you can using the Function strlen() in the String's libs

char a[20] = "asdf";
cout << strlen(a) << endl;

//the outstream is 4
useresu 2005-04-29
  • 打赏
  • 举报
回复
楼主是指的什么string?

如果是char *
strlen()

在<string.h>头文件里

如果是stl的string,
#inlcude <string>
using namespace std;

string str = "abcde";
int n;
n = str.size();
syd1207 2005-04-29
  • 打赏
  • 举报
回复
strlen()
useresu 2005-04-29
  • 打赏
  • 举报
回复
.size()
piaozi2003 2005-04-29
  • 打赏
  • 举报
回复
没听说过 strlen吗?

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧