大家好我已經做了這個簡單的程序,但在輸入書名的過程中有一些問題,程序只是跳過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