I was on Cplusplus tonight, learning a bit about data structures (which I like). Well, I copied and pasted one example, ran it, learned a bit. Then I tried the same for the second. Here's the code for the second...
// array of structures
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
#define N_MOVIES 3
struct movies_t {
string title;
int year;
} films [N_MOVIES];
void printmovie (movies_t movie);
int main ()
{
string mystr;
int n;
for (n=0; n<N_MOVIES; n++)
{
cout << "Enter title: ";
getline (cin,films[n].title);
cout << "Enter year: ";
getline (cin,mystr);
stringstream(mystr) >> films[n].year;
}
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 << " (" << movie.year << ")\n";
}
Well it compiles and runs, but gives me this output, with any imput.
[IMG]http://i9.photobucket.com/albums/a54/comnder09/Weird.jpg[/IMG]
Now thats the output for the original program its giving me. They're saved as two different files, and I've only got one open at a time, and have tried exiting and re-entering the program. Was wondering what the deal behind something like this is?