Which of the following is correct way of concatenating two string objects in C++? [code] way 1: string s1 = "hello"; string s2 = "world"; string

Quang Hiếu

New member
Which of the following is correct way of concatenating two string objects in C++?
Code:
way 1:
string s1 = "hello";
string s2 = "world";
string s3 = s1 + s2;
way 2:
string s1 = "hello";
string s2 = "world";
string s3 = s1.append(s2);
way 3:
string s1 = "hello";
string s2 = "world";
string s3 = strcat(s1,s2);
A. 1 and 2
B. 2 and 3
C. 1 and 3
D. 1, 2 and 3
 
Answer: a
Explanation: To concatenate two string objects we are provided with either direct addition or append() function in string class but strcat() is char* function hence they cannot be used to concatenate two string objects.
 

Tìm kiếm

Back
Top