The std::string class already overloads operator+() to allow string concatenation. But as you have declared your variables as pointers to strings, you need to dereference them before you can do this.
std::string *s1,*s2,*s3;
//
*s3 = (*s1)+(*s2) rather than s3=s1+s2
Now, do the rest of your homework yourself. All you have to do is type the damn things into a C interpreter.
In c language(strings) can we combine two strings by statement s3=s1+s2 if they are declaired as *s1,*s2,*s3?
no you cant, you can you apply addition operation on two strings ? be logical !
you can try the below code for string concatenation
#include%26lt;string.h%26gt;
#include%26lt;conio.h%26gt;
#include%26lt;stdio.h%26gt;
void main()
{
char s1[10],s2[10];
printf("\n enter string 1");
gets(s1);
printf("\n enter string 2");
gets(s2);
strcat(s1,s2);
puts(s1);
getch();
}
Reply:Nope.... Ucan use strcat(); function to concatenate two strings.....Go to help page of strcat() function to find how to use parameters for that function as per your needs.
U can use + to concatenate strings only using Operator Overloading (polymorphism Feature) which can be used in Object Oriented Programs like C++...
Reply:You have asked at least ten questions today, looks like all these are your project assignment, may be you can contact a freelance programmer to do it for you. Check websites like http://getafreelnacer.com/
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment