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

2024-11-02 13:32:22
推荐回答(2个)
回答1:

#include

void main()
{

char *str = "abdese";
char e = str[3];
printf("圆燃猜橘型%c", e);

}
字符串可以当数组用段亩。

回答2:

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