+ 5
How to concat,find length,copy the string
3 Answers
+ 10
Adding more to the Ipang's answer
you can also use :
strcat(str1, str2);
//str1: String to concatenate with
//str2: String to concatenate
strcpy(str1, str2);
//str1: String in which you want to copy other string
//str2: String you want to copy
//int len = strlen(str);
//returns the length of string in integer
library required :
#include <cstring>
+ 5
To concatenate string we use + operator, e.g.
std::string str1{"Solo"};
std::string str2 {"Learn"};
std::cout << str1 + str2;
To find length use length() or size() method of the object. e.g.
std::string name {"Danny"};
int strLen = name.length();
[Or this, yields same value]
int strSize = name.size();
To copy, create a new string object, passing the source string object as the copy constructor argument e.g.
std::string name {"Danny"};
std::string other (name);
std::cout << other << std::endl << name;
Hth, cmiiw
+ 4
tq u