I was trying to write a program to enter texts like passwords (display "\*" instead of the character which in input by the user).

The problem is, when I use char arrays to store the password, the program works fine, but when I use a string class variable for the same purpose, my program crashes while displaying the string.

Here is the code:

```
 // *********THIS CODE WORKS FINE***********

#include <iostream>
#include<string>
#include<conio.h>

int main()
{ 
    using namespace std;

    int i=0;
    cout<<"Enter a password,press ENTER to finish writing"<<endl;
    char passw[20];

    passw[i]=getch();

    while(passw[i]!=13)
    {
        i++;
        cout<<"*";
        passw[i]=getch();
    }
    passw[i+1]='\0';
    cout<<"\nPassword is "<<passw;

    return 0;
}

```

Now when I replace `char passw[20]` with `string passw`:

```
//**********THIS CODE CRASHES!!*********

#include <iostream>
#include<string>
#include<conio.h>

int main()
{ 
    using namespace std;
    int i=0;
    cout<<"Enter a password,press ENTER to finish writing"<<endl;
    string passw;

    passw=getch();

    while(passw[i]!=13)
    {
        i++;
        cout<<"*";
        passw[i]=getch();
    }

    cout<<"\nPassword is "<<passw;

    return 0;
}

```

Can anybody explain why this is happening? 

Just started with strings and there's just too much for me to know about strings :)