Actually it is necessary that where you need to enter the date of withdrawal, you could enter a whole line, for example, 12 July, and not just the word

#include "pch.h" #include <iostream> #include <string> using namespace std; struct itemsinfo { string dateiz; string nameofitem; int amount; float costdollars; }; int main() { int size; cout << "Enter size: "; cin >> size; itemsinfo *item = new itemsinfo[size]; //динамичСский массив Π½Π° Π²Π²Π΅Π΄Π΅Π½ΠΎΠ΅ ΠΊΠΎΠ». элмСнтов for (int i = 0; i < size; i++) { cout << "enter date of withdrawal: "; //Π½ΡƒΠΆΠ½ΠΎ ввСсти Π΄Π°Ρ‚Ρƒ ΠΈΠ·ΡŠΡΡ‚ΠΈΡ cin >> item[i].dateiz; cout << "enter name of item: "; //Π½ΡƒΠΆΠ½ΠΎ ввСсти Π½Π°Π·Π²Π°Π½ΠΈΠ΅ ΠΏΡ€Π΅Π΄ΠΌΠ΅Ρ‚Π° cin >> item[i].nameofitem; cout << "enter amount: "; //Π½ΡƒΠΆΠ½ΠΎ ввСсти количСство cin >> item[i].amount; cout << "enter cost in dollars: "; //Π½ΡƒΠΆΠ½ΠΎ ввСсти ΡΡ‚ΠΎΠΈΠΌΠΎΡΡ‚ΡŒ cin >> item[i].costdollars; cout << "=============================" << endl; } 
  • What is the problem with existing code? - Enikeyshchik

1 answer 1

Use std::getline instead of the >> operator, while remembering to remove the remnants of the previous input from the input buffer using cin.ignore

 std::cout << "enter date of withdrawal: "; std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); std::getline(std::cin, item[i].dateiz);