为了账号安全,请及时绑定邮箱和手机立即绑定

为什么在@处提示有错误,该怎么改?

为什么在@处提示有错误,该怎么改?

C++
胡子哥哥 2023-03-15 21:17:36
比如说:string="abcde"; 有没有可以提取其中某个字符的函数,比如提取第三个‘c’. 另外, #include <iostream> #include <string> using namespace std; void main() { string s="meum"; int n=strlen(&s); //@ cout<<s[1]<<endl; if(s[3]==101) cout<<"hhh"<<endl; else cout<<"55"; }  小弟先谢过了,:-)
查看完整描述

2 回答

?
梵蒂冈之花

TA贡献1900条经验 获得超5个赞

nt n = strlen(s.c_str())才对。
s是string类型,不能被strlen函数直接处理,要转换成C风格的字符串,就用c_str()方法。
但是转换后是一个const指针,要注意使用。

查看完整回答
反对 回复 2023-03-18
?
叮当猫咪

TA贡献1776条经验 获得超12个赞

#include <iostream>
#include <string>
using namespace std;
int main()
{
string a="asfsadf";
cout<<a[4]<<endl;
system("pause");
return 0;
}///
///
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s="meum";
int n=strlen(s.c_str()); 
cout<<s[1]<<endl;
if(s[3]==101)
cout<<"hhh"<<endl;
else
cout<<"55";
system("pause");
return 0;
}

 


查看完整回答
反对 回复 2023-03-18
  • 2 回答
  • 0 关注
  • 70 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信