To enter a string, I was instructed to use gets(str) rather than cin.
In the programme below, though, I can use cin perfectly well.
Could you please tell me if you can use cin?
Please accept my apologies for my poor English.
The application allows you to enter up to five names and then print them on the screen.
The code is as follows:
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char **p = new char *[5];
for (int i = 0; i < 5; i++)
{
*(p + i) = new char[255];
} //make a 2 dimensional array of strings
for (int i = 0; i < n; i++)
{
char n[255] = "";
cout << "insert names: ";
cin >> n; //how i can use cin here to insert the string to an array??
strcpy(p[i], n);
}
for (int i = 0; i < n; i++)
{
cout << p[i] << endl; //print the names
}
}