0

I want to store the full name in array with whitespace but when I type the name, the run to exit. Can you guys help me?

int main()
{
int user1, user2;
char name[100][10000];
int num[10000];
int temp;
cout << "Number of students: "; cin >> user1; cout << "\n";
for(int i = 0; i < user1; i++)
{
    cout << "Students No." << i + 1; 
    cout << "\nName: "; cin >> name[i];
    cout << "Num: "; cin >> num[i];
    cout << "\n";
}
  • After you start using `getline`, you will also need to be aware of [its behavior](https://stackoverflow.com/questions/21567291/why-does-stdgetline-skip-input-after-a-formatted-extraction) when mixed with non-string input. – NathanOliver Jun 27 '22 at 14:38
  • Save yourself some headaches. Use `std::string` for text. Use `std::vector` for your container. – Thomas Matthews Jun 27 '22 at 16:52
  • Looks like you are using *parallel arrays*. Prefer to put fields into a `struct` and then have a `std::vector` of the `struct`. Parallel arrays can become unsynchronized and may cause data cache reloads. The `struct` will allow the fields to be close together and usually on the same cache line. – Thomas Matthews Jun 27 '22 at 16:54

0 Answers0