大家好我已经做了这个简单的程序,但在输入书名的过程中有一些问题,程序只是跳过cin.get()函数,然后返回0,而我不知道为什么它不工作,虽然没有错误。任何帮助,将不胜感激。谢谢cin.get()不适用于字符数组
#include<iostream>
using namespace std;
struct book
{
private:
int bookid;
char name[30];
float price;
public:
input()
{
cout<<"\n Enter book ID: ";
cin>>bookid;
if(bookid<0)
{
bookid = -bookid;
}
cout<<"\nEnter book title: ";
cin.get(name,30); // here is the problem
cout<<"\nEnter book price: ";
cin>>price;
}
display()
{
cout<<"\nBook ID: "<<bookid<<"\nbook title: "<<name<<"\nprice: "<<price;
}
};
int main()
{
book b1;
b1.input();
b1.display();
return 0;
}
你是不是指什么意思? – NathanOliver
什么是不专门工作?在Stack Overfow上询问问题时,始终发布[MCVE],包括所有错误消息,输入和预期输出。 –
当我运行它时,跳过cin.get()函数 – Waleed