Why does this program crashes?

No, no, no, just use std::string! Easier to use, and easier to understand!

#include <string>
using namespace std;  

int main(){
    string name,add;
    cout<<"Name: ";
    getline(cin, name); // A name probably has more than 1 word
    cout<<"\n\tadd: ";
    cout<<"\n\t Add:"<<add;
    return 0;

As far as your problem goes with your original code, it is that you haven’t allocated any memory for your char*, and are reading into memory that isn’t yours.

Browse More Popular Posts

Leave a Comment