Отсутствует оператор ">>", соответствующий этим операндам 29,31 класс

#include <iostream>
#include <iostream> 
#include "windows.h"

using namespace std;

#define N 4

class medcine
{
    int count;
    long price;
public:
    char name[50];
    void SetCount(int count) { this->count = count; }
    int GetCount(){ return count; } 
    void SetPrice(int price) { this->price = price; }
    int GetPrice() { return price; }
};

void Fill_Information(medcine x[])
{
    for (int i = 0; i < N; i++)
    {
        cout << "########################" << endl;
        cout << "Назва: ";
        cin >> x[i].name;
        cout << "Кількість(шт.): ";
        cin >> x[i].GetCount();
        cout << "Ціна(грн.):";
        cin >> x[i].GetPrice();
        cout << endl;
    }
}

int main()
{
    SetConsoleCP(1251);
    SetConsoleOutputCP(1251);

    medcine x[N];
    Fill_Information(x);
    char word[20];
    int sum = 0;
    cout << "Назва товару: ";
    cin >> word;
    cout << "Кількість: ";
    for (int i = 0; i < N; i++)
    {
        if (strcmp(word, x[i].name) == 0)
        {
            cout << x[i].name << ",";
            sum += x[i].GetPrice();
        }
    }
    cout << endl << "Обсяг товару: " << sum << endl;
}

Ответы (1 шт):

Автор решения: Harry

Поскольку

x[i].GetCount();

возвращает значение типа int (а не ссылку!), то

cin >> x[i].GetCount();

сродни

cin >> 55;

Вот и не удается ничего читать — потому что непонятно, куда именно читать.

Вот вариант исправления:

void Fill_Information(medcine x[])
{
    for (int i = 0; i < N; i++)
    {
        int count; long price;
        cout << "########################" << endl;
        cout << "Назва: ";
        cin >> x[i].name;
        cout << "Кількість(шт.): ";
        cin >> count;
        x[i].SetCount(count);
        cout << "Ціна(грн.):";
        cin >> price;
        x[i].SetPrice(price);
        cout << endl;
    }
}
→ Ссылка