well here some stuff that i didnt get
at this code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
// example about structures
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
struct movies_t {
string title;
int year;
} mine, yours;
void printmovie (movies_t movie);
int main ()
{
string mystr;
mine.title = "2001 A Space Odyssey";
mine.year = 1968;
cout << "Enter title: ";
getline (cin,yours.title);
cout << "Enter year: ";
getline (cin,mystr);
stringstream(mystr) >> yours.year;
cout << "My favorite movie is:\n ";
printmovie (mine);
cout << "And yours is:\n ";
printmovie (yours);
return 0;
}
void printmovie (movies_t movie)
{
cout << movie.title;
cout << " (" << movie.year << ")\n";
}
|
about the part of movie.title and the parameter void printmovie (movies_t movie) how he used movie here or why :O
the second thing over here
getline (cin,mystr);
stringstream(mystr) >> yours.year;
why he used another string and then saved the string in our variable yours.year
in another words why didnt he just
getline (cin,yours.year) ? it gives error at c++
1>c:\users\xxxxxxx\documents\visual studio 2010\projects\t2\t2\t2.cpp(27): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &' from 'int'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(479) : see declaration of 'std::getline'
one more thing
at this code
#define N_MOVIES 3
does he define N_MOVIES 3 as array of 3 ? :O sorry i know they maybe stupid but my poor english doesnt help me to fully understand that