c++中如何提取出一个字符串中的几个字符?

比如有一串字符‘abdese’,我想提取他们当中的第三个‘e’,怎么做可以做到呢?

第1个回答  2007-04-06
#include <stdio.h>

void main()
{

char *str = "abdese";
char e = str[3];
printf("%c", e);

}
字符串可以当数组用。
第2个回答  推荐于2016-02-18
string str="abdese";

char ch = str[3];

string s("What we have here is a failure to communicate");

string sub = s.substr(21);

cout << "The original string is " << s << endl;
cout << "The substring is " << sub << endl;

displays

The original string is What we have here is a failure to communicate
The substring is a failure to communicate本回答被提问者采纳
相似回答