M
Makwana
I am a grad student trying to get my hands on c++. I am trying to code
simple programs using pointers and it would be great if some gurus
here point me to the correct method of referencing.
My code complies but crash's .. can someone point me the right way to
do it. Thanks in advance!
*******************************************************************************************************************************
// pointers to structures
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
struct movies_t {
string title;
int year;
};
int main ()
{
string mystr;
int mov_num,i;
cout << " Enter the number of movies you want to enter " << endl;
cin >> mov_num;
movies_t amovie[mov_num];
movies_t * pmovie[mov_num];
// strcpy(&amovie, pmovie);
// pmovie = &amovie;
for (i=0;i<mov_num;i++);
{
cout << "Enter title: " << endl;
getline (cin, pmovie->title);
cout << "Enter year: " << endl;
getline (cin, mystr);
(stringstream) mystr >> pmovie->year;
}
for (i=0;i<mov_num;i++);
cout << "\nYou have entered:\n";
cout << pmovie->title;
cout << " (" << pmovie->year << ")\n";
system ("pause");
return 0;
}
simple programs using pointers and it would be great if some gurus
here point me to the correct method of referencing.
My code complies but crash's .. can someone point me the right way to
do it. Thanks in advance!
*******************************************************************************************************************************
// pointers to structures
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
struct movies_t {
string title;
int year;
};
int main ()
{
string mystr;
int mov_num,i;
cout << " Enter the number of movies you want to enter " << endl;
cin >> mov_num;
movies_t amovie[mov_num];
movies_t * pmovie[mov_num];
// strcpy(&amovie, pmovie);
// pmovie = &amovie;
for (i=0;i<mov_num;i++);
{
cout << "Enter title: " << endl;
getline (cin, pmovie->title);
cout << "Enter year: " << endl;
getline (cin, mystr);
(stringstream) mystr >> pmovie->year;
}
for (i=0;i<mov_num;i++);
cout << "\nYou have entered:\n";
cout << pmovie->title;
cout << " (" << pmovie->year << ")\n";
system ("pause");
return 0;
}