The C++ standard requires that headers were declared without extension .h and standard C headers were prefixed by letter 'c'.
#include <
iostream>
#include <conio.h>
#include <
cstdlib>
Function main shall have return type int:
int main()
It would be better to define some named constant for the arbitrary number 15
const int N = 15;
char str1[N], str2[N];
For entering string literals in a character array it is better to use getline function.
Either you shall specify nested name specifier std:: as
std::cout<<"Enter any string = ";
or use directive using namespace std;
There is no need to define variable i because it is used only inside the loop.
The loop itself could look the following way
for ( int i = 0; str2[i] = str1[i]; i++ );
Taking into account all comments the code could look the following way
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream>
#include <conio.h>
#include <cstdlib>
int main()
{
const int N = 15;
char str1[N], str2[N];
std::cout << "Enter any string (no more than " << N << " char) = ";
std::cin.getline( str1, N );
for ( int i = 0; str2[i] = str1[i]; i++ );
std::cout << str2;
getch();
return 0;
}
|