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

比如说: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"; 

}  
小弟先谢过了,:-)

胡子哥哥
浏览 72回答 2
2回答

梵蒂冈之花

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

叮当猫咪

#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());&nbsp;cout<<s[1]<<endl;if(s[3]==101)cout<<"hhh"<<endl;elsecout<<"55";system("pause");return 0;}&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP