Hey. There is a structure where we have to write information about the owner, full name and phone number .. If you enter> 1 words in the full name (separated by a space, i.e. first name, last name), then he will not ask for the number, but THEN, when deducing in the num number field, it will display the second word of the full name (that after the space).
It is necessary that the program can read a few words ... Thanks in advance. Code:
using namespace std; struct owner { char FIO [19], num[9]; }a[9]; int main () { cout << "BBEDuTE KOJIu4ECTBO BJIADEJIbTCEB: "; int n; cin >> n; for (int i=0; i<n; i++) { cout << "\n BJIADEJIETC[" << i+1<<"]"; cout << "\n FIO "; cin >> a[i].FIO; cout << " num "; cin >> a[i].num; } for (int i=0; i<n; i++) { cout << "\n BJIADEJIETC[" << i+1<<"]"; cout << "\n FIO "; cout << a[i].FIO; cout << " num "; cout << a[i].num; } }
instead of cin
I tried cin.get(a[i].FIO)
and gets(a[i].FIO)
, but gets(a[i].FIO)
error ... I tried the string
with getline (cin, a[i].FIO)
is also an error. ..
PS: I understand that cin reads only 1 word, but I don’t know how to fix it.