C++ Program to copy string without using strcpy() function
In this program, You will learn how to copy string without using strcpy() function in C++.
while (str1[i] != '\0') {
str2[i] = str1[i];
i++;
}
Example: How to copy string without using strcpy() function in C++.
#include<iostream>
using namespace std;
int main() {
char str1[100], str2[100];
int i = 0, k;
cout << "Enter string value:";
cin.getline(str1, 100);
while (str1[i] != '\0') {
str2[i] = str1[i];
i++;
}
str2[i] = '\0';
cout << "First string is:" << str1;
cout << "\nSecond Copy String is :" << str2;
return 0;
}
Output:
Enter string value:Xiith.com
First string is:Xiith.com
Second Copy String is :Xiith.com