比如说: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贡献1651条经验 获得超5个赞
nt n = strlen(s.c_str())才对。
s是string类型,不能被strlen函数直接处理,要转换成C风格的字符串,就用c_str()方法。
但是转换后是一个const指针,要注意使用。

叮当猫咪
TA贡献1543条经验 获得超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;
}
- 2 回答
- 0 关注
- 7 浏览
添加回答
举报
0/150
提交
取消