Need to recognise Enter as a character

Hey guys,

So I have the following part of my function which changes the entries of some members in my struct:

1
2
3
4
5
cout << "Enter new status (existing: " << database[entryNumber].status << "): ";
	cin >> database[entryNumber].status;
	cout << "Enter new Rego (existing: " << database[entryNumber].rego << "): ";
	cin >> database[entryNumber].rego;
	cout << "Enter Make (existing: " << database[entryNumber].make << " ):";


If the user presses enter without entering any changes (i.e. want the current information in the database to stay the same) I need it to keep the existing entry and for the program to continue to the next field change. Obviously, when the user wishes for the entry to be changed and enters the new information and it replaces the current entry in the database.

Any ideas?

Cheers!
Use a temporary string (instead of filling the field directly). Do something with it only if it is not empty.
But the problem is, I cannot have an empty string. When I press enter it waits for me to input a character/s. I need the program to continue on when I press enter.
Use getline() instead of cin >> str: getline(cin, str);

See: http://www.cplusplus.com/reference/string/getline/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void edit(int entryNumber, int numberOfEntries)

{

	char in[20];

	//Clear cin from previous selection in order for the below to work.

	cin.ignore();



	cout << "Enter new status (existing: " << database[entryNumber].status << "): ";

	cin.getline(in, 20);

   	if (in[0] != '\0')

		strcpy(database[entryNumber].status,in);

        ...


Works perfectly! Cheers!
Topic archived. No new replies allowed.