One thing I am wondering is how to I put a string of info into a multidimensional array?
Let me specify the array:
Now in one of my functions I need to input between 1 to 10 different names into that array.Code:char name[10][80];
I have tried three different ways, each being unsuccessful. Let me show you the ways I have tried. The first being the only one where I have got some result, but I need it to include spaces.
Obviously that would only input everything up until a whitespace character.Code:for (i = 0; i < 10; i++) { cin >> name[i]; ... }
I tried the following two methods which I though would've worked, but didn't...
Code:#include <cstring> ... for (i = 0; i < 10; i++) { gets(name[i]); ... }Code:for (i = 0; i < 10; i++) { cin.getline(name[i], 80, '\n'); ... }
Here is a snippet of my code and it's output with effort 2.
Code:void enter() { int i; for (i = 0; i < 10; i++) { cout << "\n\nEnter employee's name: "; gets(name[i]); cout << "Enter phone number: "; gets(phone[i]); cout << "Enter number of hours worked: "; cin >> hours[i]; cout << "Enter wage: "; cin >> wage[i]; } }One more question, what's the difference between gets() and cin.getline() anyhow? Is there a better one to use?Code:Enter employee's name: Enter phone number:
I'm probably just doing something extremely stupid, but I'm still new at this so take it easy on me![]()



LinkBack URL
About LinkBacks



