我試着運行下面的代碼,但一次輸入後,其餘的輸入被初始化爲零,並自動顯示在屏幕上。我哪裏做錯了?此代碼運行不正常
#include<iostream>
#define N 50
using namespace std;
struct movies_t
{
char title[60];
int year;
}user[N];
void printmovie(movies_t);
int main()
{
for(int i = 0; i < N; i++)
{
cout << "Enter title: ";
cin.get(user[i].title, 60);
cout << "Enter year: ";
cin >> user[i].year;
}
cout << "\nYou have entered these movie: \n";
for(int i = 0; i < N; i++)
printmovie(user[i]);
return 0;
}
void printmovie(movies_t m)
{
cout << m.title;
cout << " (" << m.year << ")\n";
}
這是C++而不是C =) –
編輯標籤不能與C – xaxxon
它與你沒有從CIN清理出的新行做..但我不記得如何解決它..像cin.flush()之類的東西。 – xaxxon