Home  • Online Tips • VCampus Help
// pointers to structures
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
struct movies_t {
string title;
int year;
};
int main ()
{
string mystr;
movies_t amovie;
movies_t * pmovie;
pmovie = &amovie;
cout << "Enter title: ";
getline (cin, pmovie->title);
cout << "Enter year: ";
getline (cin, mystr);
(stringstream) mystr >> pmovie->year;
cout << "
You have entered:
";
cout << pmovie->title;
cout << " (" << pmovie->year << ")
";
return 0;
}

Comments 5


can anyone please explain me line number 17, 19 and 20
line 17 taking a line input to the instance variable amovie->title  by conjunction with getline() and cin core object
17 and 19 is almost same. here mystr is string variable in main function
assigning mystr's value to pmovie->year with casting by (stringstream)
thnx Smaile
About Author
Arshiful Islam Shadman
Copyright © 2024. Powered by Intellect Software Ltd