cin>> not work with getline()

后端 未结 2 1644
长情又很酷
长情又很酷 2020-12-12 06:20
#include 
#include 
using namespace std;

int main () {
  string str;
  int age;
  cout << \"Please enter age: \";
  cin>>a         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 07:04

    getline() won't work with an int, or any number for that matter. It is defined as such:

    istream& getline (char* s, streamsize n );
    
    istream& getline (char* s, streamsize n, char delim );
    

    So, it takes in strings and char*'s; not digits.

提交回复
热议问题