When I run the program, it does not print the last line on the screen. For example, if I tell you to make room for 3 string
then just ask me two times and print only 2 the first two strings that I type.
I want to know why this happens and what is the solution to this problem.
My code is as follows:
#include <iostream>
#include <string>
using namespace std;
void numeroPalabras(string &palabras,int &num, string *&p)
{
cout << ">>: ";
cin >> num;
p = new string[num];
for (int i = 0; i < num ; i++)
{
getline(cin, p[i]);
}
}
void presentar(string *&p, const int &num)
{
for (int i = 0; i < num; i++)
cout << *p++ << endl;
}
int main()
{
int num;
string palabras;
string *p;
numeroPalabras(palabras, num, p);
presentar(p,num);
delete p;
/* code */
return 0;
}