简体   繁体   中英

cin.get() error

I'm fairly new to C++ and in need of some understanding for the function cin.get(). I wrote this function and I'm getting an error on this line

string getName(string& name){
    cout<<"Enter your full name: ";
    cin.get(cin,name);      //this line
    return name; 
}

Specifically, I am getting an error on the . , the error stating:

no instance of overloaded function

Replace this line:

cin.get(cin,name);

with this:

cin >> name

Edit: According to your latest comment to deal with with spaces you can use this:

cin >> skipws >> name;

You need to use a c-style string to get the name-lastname first:

string getName(string& name){
  char str[256];
  cout<<"Enter your full name: ";
  cin.get(str, sizeof(str));
  return name = str; 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM