S
S
SouLWorker2020-05-03 18:34:58
C++ / C#
SouLWorker, 2020-05-03 18:34:58

Error entering a string in a class, how to solve?

The following error pops up
5eaee411c2213737990286.jpeg

:

#pragma once
#include <iostream>
#include <string>
using namespace std;

class Producer_of_Fuel
{
public:
  Producer_of_Fuel();
  ~Producer_of_Fuel();
  void set_name_producer();
  void set_country();
  void get_name_producer();
  void get_country();
protected:
  string name_producer[20];
  string country[20];
};


Function:
void Producer_of_Fuel::set_country()
{
  cout << "Pls, write country of producer" << endl;
  cin >> country;
}

Tell me how to fix it if you write like this,
void Producer_of_Fuel::set_country()
{
  cout << "Pls, write country of producer" << endl;
  cin >> country[20];
}

that doesn't help at all

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-05-03
@SouLWorker

country - an array of string. What for? It's not C, simple enough:
string country;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question