char* and cin in C++
问题 I would like to input a string of indefinite length to a char * variable using cin; I can do this: char * tmp = "My string"; cout << tmp << endl; system("pause"); It works perfectly. But I fail to do this: char * tmp cin >> tmp; Could you give me a hing what's wrong" 回答1: Well, you havn't created an object for the char* to point to. char* tmp = new char[MAX_LENGTH]; should make it work better (you have to define MAX_LENGTH). Another way to do this is: std::string strtmp; cin >> strtmp; const