the code given below does not work.
please teach me

Code:
void function(string str1)
{
string str2;
int i=0;
while(str1[i]!=NULL)
{
str2[i]=str1[i];
i++;
}
}
|
Newbie Member
|
|
| 7Mar2012,19:54 | #1 |
|
how to copy one string into another using LOOPS.(i am talking about default string class)??
the code given below does not work. please teach me ![]() Code:
void function(string str1)
{
string str2;
int i=0;
while(str1[i]!=NULL)
{
str2[i]=str1[i];
i++;
}
}
|
|
Mentor
|
![]() |
| 8Mar2012,06:34 | #2 |
|
Your chosen approach is not the correct one. Simply use the assignment operator:
Code:
string str1="Hello"; string str2=str1; cout<<str2; |