如题所述
1、定义和构造初始化,string 提供了很多构造函数,可以以多种方式来初始化string字符串。
2、赋值,拼接字符串,string重载了 = + += 等多种运算符。
3、访问字符操作,string可以按数组方式,以下标来访问。还可以用at()函数访问指定的字符。
4、可以使用 STL 的接口,可以把 string 理解为一个特殊的容器,容器中装的是字符。
5、比较操作 == != > >= < <= compare 等,string的比较操作,按字符在字典中的顺序进行逐一比较。在字典前面的字符小于后面的字符。
6、查找 find rfind ,string中除了find、rfind,还有find_first_of等函数也提供了强大的查找功能。
温馨提示:答案为网友推荐,仅供参考
第1个回答 推荐于2018-02-28
#include<stdio.h>
#include<string.h>
void addspace(char *s,char *b){
int l=strlen(s);
int lb=2*l-1;
int i;
for(i=0;i<lb;i++)
*(b+i)=i%2?' ':*(s+i/2);
*(b+lb)=*(s+l);
}
int main(){
int i,l;
char s[150],b[300];
printf("请输入一串字符:");
scanf("%s",s);
addspace(s,b);
printf("加空格后的字符串:%s\n",b);
return 0;
}
#include<string.h>
void addspace(char *s,char *b){
int l=strlen(s);
int lb=2*l-1;
int i;
for(i=0;i<lb;i++)
*(b+i)=i%2?' ':*(s+i/2);
*(b+lb)=*(s+l);
}
int main(){
int i,l;
char s[150],b[300];
printf("请输入一串字符:");
scanf("%s",s);
addspace(s,b);
printf("加空格后的字符串:%s\n",b);
return 0;
}
运行结果:
请输入一串字符:abcdefgh
加空格后的字符串:a b c d e f g h
本回答被网友采纳第2个回答 2016-11-21
#include<stdio.h>
int main()
{char s[200],*p,*q;
printf("Enter a string:");
scanf("%s",s);
for(p=q=s;*p;p++,q+=2);
for(*--q=0,*p--;p>s;)
{*--q=*p--;*--q=' ';}
puts(s);
return 0;
}
第3个回答 2016-11-21
第4个回答 2016-11-21
int main()
{
#define MAX_SIZE 1024
char c[MAX_SIZE] = {0};
printf("input one string:");
scanf("%s", c);
int n = 0;
char *p = c;
char achOut[MAX_SIZE * 2] = {0};
while(*p != '\0')
{
achOut[n++] = *p++;
achOut[n++] = ' ';
}
printf("%s", achOut);
}本回答被提问者采纳
{
#define MAX_SIZE 1024
char c[MAX_SIZE] = {0};
printf("input one string:");
scanf("%s", c);
int n = 0;
char *p = c;
char achOut[MAX_SIZE * 2] = {0};
while(*p != '\0')
{
achOut[n++] = *p++;
achOut[n++] = ' ';
}
printf("%s", achOut);
}本回答被提问者采纳