在c+;中使用getline函数进行输入时忽略第一个字符+; 为什么在C++程序中使用GETLIN输入会自动忽略输入的第一个字母? 我该怎么解决这个问题

在c+;中使用getline函数进行输入时忽略第一个字符+; 为什么在C++程序中使用GETLIN输入会自动忽略输入的第一个字母? 我该怎么解决这个问题,c++,C++,编辑1:我在同一程序的其他函数中使用了getline和cin.ignore(),但它在那里工作得很好 cout<<"Enter the roll no: "; cin.ignore(); getline(cin,rollno); cout<<"Enter the name of book you want to issue:"; cin.ignore();

编辑1:我在同一程序的其他函数中使用了getline和cin.ignore(),但它在那里工作得很好


    cout<<"Enter the roll no: ";        
    cin.ignore();
    getline(cin,rollno);
    cout<<"Enter the name of book you want to issue:";  
    cin.ignore();                                       
    getline(cin,input);                 //input= think and row rich
    cout<<"What's the return data";
    cin.ignore();
    getline(cin,input_date);           // input=20-8-2019

    cout<<input<<" "<<input_date<<endl;      //output of inputs = hink and grow rich and 0-8-2019



你可以用
cin.ignore()告诉它吗
它应该在没有
cin.ignore()的情况下工作
这是一个吗?你知道cin.ignore()的功能和使用时间吗?@johnnympp。如果没有cin.ignore(),我们不能对字符串使用getline函数。它将第一次输入,然后不会要求第二次和第三次输入。@BilalKhan这是错误的。你为什么这么想?当你说程序“不接受任何输入”时,你的确切意思是什么?到底出了什么问题?(我怀疑您一直在代码周围散布
cin.ignore()
,以使其在不了解您需要它的地方和原因的情况下工作,就像在这里一样,您在没有意义的地方拥有它。)提示:只在您特别需要忽略某些内容时使用它。@DavidSchwartz,我已经尝试过不使用cin.ignore()而且它工作不正常输入卷号:输入您想要发行的书的名称:``我已经再次执行了代码,这里它没有要求我卷号!!!所有
istream和ignore(streamsize n=1,int-delim=EOF)
does是声明问题中给出的示例中未使用的函数。如果这对运行时有影响,那么代码中的其他地方就有一个错误,该错误通过不声明此函数而以某种方式暴露出来。
    cout<<"Enter the roll no: ";
    istream& ignore (streamsize n = 1, int delim = EOF);  //by using this line my code starts working properly.
    cin.ignore();
    getline(cin,rollno);
    cout<<"Enter the name of book you want to issue:";
    getline(cin,input);
    cout<<"What's the return data";
    getline(cin,input_date);