请学过c++的兄弟回答一下

来源:百度知道 编辑:UC知道 时间:2024/06/16 12:42:12
程序
// array of structures
#include ‹iostream.h›
#include ‹stdlib.h›

#define N_MOVIES 5

struct movies_t {
char title [50];
int year;
} films [N_MOVIES];

void printmovie (movies_t movie);

int main () {
char buffer [50];
int n;
for (n=0; n
cout << "Enter title: ";
cin.getline (films[n].title,50);
cout << "Enter year: ";
cin.getline (buffer,50);
films[n].year = atoi (buffer);
}

cout << "\nYou have entered these movies:\n";
for (n=0; n
printmovie (films[n]);
return 0;
}

void printmovie (movies_t movie) {
cout << movie.title;
cout << " (" << movie.year << ")\n";
}
运行结果
Enter title: Alien
Enter year: 1979
Enter title: Blade Runner
Enter year: 1982
Enter title: Matr

你貌似是否搞错了,你那代码for你是否删了- -||
写成int n;for(n=0,n!=0,n++)可以吗?//这个你也写错了,中间的要分号

如果按你写成那样,程序是没错,但这意思就表明无限下去,根本不能停止,
这显然运行不了- -|

#include <iostream>
#include <stdlib.h>
using namespace std;
#define N_MOVIES 5

struct movies_t {
char title [50];
int year;
} films [N_MOVIES];

void printmovie (movies_t movie);

int main () {
char buffer [50];
int n;
for (n=0; n< N_MOVIES;n++)
{cout << "Enter title: ";
cin.getline (films[n].title,50);
cout << "Enter year: ";
cin.getline (buffer,50);
films[n].year = atoi (buffer);
}

cout << "\nYou have entered these movies:\n";
for (n=0; n<N_MOVIES;n++)
printmovie (films[n]);
return 0;
}

void printmovie (movies_t movie) {
cout << movie.title;
cout << " (" <&