C++ 连接 字符串

来源:百度知道 编辑:UC知道 时间:2024/06/15 01:18:47
要求1:字符串A在前,B在后连接成新的字符串
2:字符串B在前,A在后连接成新的字符串
3:判断字符串A与B是否完全相同
4:判断字符串A是否包含有字符串B
5:判断字符串B是否包含有字符串A

速度~!拜托了,考试~~!
...补充下,我基本都完全忘记怎么编程了,各位大大麻烦把所有命令都发上来
万分感激!!!
考试通过一定再追分!!!

你的字符串是什么类型的啊?
是const char*还是std::string?
如果是std::string;

std:string A("This is string A");
std:string B("This is string B");

std::string n = A + B;
if (A == B) then std:cout << "Equal!"<<std::endl;
if (A.find(B)) the std::cout << "A contains B"<<std::endl;
if (B.find(A)) the std::cout << "B contains A"

1:字符串A在前,B在后连接成新的字符串 strcat_s (a,b)

2:字符串B在前,A在后连接成新的字符串 strcat_s (b,a)

3:判断字符串A与B是否完全相同 if (_tcscmp(a,b))

4:判断字符串A是否包含有字符串B
stfind (a,b)
5:判断字符串B是否包含有字符串A stfind (b,a)

string A("stringA"),B("stringB");
1.A.append(B)//A="stringAstringB"
2.B.append(A)//B="stringBstringA"
3.if(A == B)
4.if(A.find(B.c_str(),0,B.length())!=-1);
4.if(B.find(A.c_str(),0,A.length())!=-1);

string A,B;
1)string C = A+B;
2)string C =