hello i have a problem i used an structure to make a database
of movies that the user sow i came from the tutorial on the site
i just made it to interact with a user
// array of structures//
#include <iostream>
#include <string>
#include <sstream>
usingnamespace std;
struct movies_t {
string title;
int year;
};
void printmovie (movies_t movie);
movies_t * pointer;
int main ()
{
string mystr;
int n,size;
cout <<"enter how mov"; //the amount of movies you want to enter//
cin >> size;
pointer = new movies_t [size];
for (n=0; n<size; n++)
{
cout << "Enter title: ";
cin >> pointer[n].title; /*if i use the getline (cin,pointer[n].title)
my program skip the cout << "enter title and the
getline (cin,pointer[n].title and goes to the cout << enter year*/
cout << "Enter year: ";
cin >> pointer[n].year;
}
cout << "\nYou have entered these movies:\n";
for (n=0; n<size; n++)
printmovie (pointer[n]);
cin >> size;
return 0;
}
void printmovie (movies_t movie)
{
cout << movie.title;
cout << " (" << movie.year << ")\n";
}
This happens because cin >> leaves the newline char in the input stream. Then getline finds that newline and therefore an empty string is read. To prevent this, use cin.ignore() after cin >>. cin.ignore discards a number of chars in the stream until a delimiter is found. The arguments you should use are cin.ignore(numeric_limits<streamsize>::max(), '\n');