私は現在、私のメインで配列を宣言し、ユーザー入力と配列に格納します。私は始めましたが、私はエラーbinary '>>': no operator found which takes a right-hand operand of type 'CDistance'
に走っています私は#include <string>
も私のコードに含まれています。このエラーは、機能void inputDist(CDistance distList[], int size)
の下で発生します。以下は完全なコードです。すべてのフィードバックは高く評価されます。ありがとう。C++オペレータ ">>"はこれらのオペランドと一致しません。
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
class CDistance
{
private:
int feet;
int inches;
int feet2;
int inches2;
public:
CDistance();
CDistance(int, int, int, int);
~CDistance();
CDistance printAndAdd(const CDistance distList[], int size);
void setDistt();
void printDistt() const;
void add(const CDistance&) const;
void subtract(const CDistance&) const;
void menu(const CDistance&) const;
void inputDist(CDistance distList[], int size);
};
CDistance::CDistance()
{
feet;
inches;
feet2;
inches2;
}
CDistance::CDistance(int f, int i, int f2, int i2)
{
feet = f;
inches = i;
feet2 = f2;
inches2 = i2;
}
CDistance::~CDistance()
{
}
void CDistance::setDistt()
{
cout << "Enter the first set of feet: ";
cin >> feet;
cout << "\nEnter the second set of feet: ";
cin >> feet2;
cout << "\nEnter the first set of inches: ";
cin >> inches;
cout << "\nEnter the second set of inches: ";
cin >> inches2;
}
void CDistance::printDistt() const
{
cout << "Feet: " << feet << "," << feet2 << endl << "Inches: " << inches << "," << inches2 << endl;
}
void CDistance::add(const CDistance& total) const
{
int totFeet = feet + feet2;
int totInches = inches + inches2;
if (totInches >= 12)
{
totInches = totInches/12;
int newFeet = totInches;
totFeet = totFeet + newFeet;
}
cout << totFeet << " feet" << endl;
cout << totInches << " inches" << endl;
}
void CDistance::subtract(const CDistance& total) const
{
int totFeet = feet - feet2;
int totInches = inches - inches2;
if (totInches >= 12)
{
totInches = totInches/12;
int newFeet = totInches;
totFeet = totFeet - newFeet;
}
cout << totFeet << " feet" << endl;
cout << totInches << " inches" << endl;
}
void CDistance::menu(const CDistance& total) const
{
CDistance m(feet, inches, feet2, inches2);
int choice;
bool menuGo = true;
while (menuGo != false)
{
{
cout <<
"\nWhat would you like to do?"
"\n1: Add "
"\n2: Subtract "
"\n3: Exit" << endl;
cin >> choice;
}
switch (choice)
{
case 1:
cout << "You chose to add" << endl;
m.add(total);
break;
case 2:
cout << "You chose to subtract" << endl;
m.subtract(total);
break;
case 3:
cout << "Please enter 5 digits to enter into the array: ";
m.inputDist;
case 4:
cout << "Goodbye" << endl;
menuGo = false;
break;
default:
cout << "Not a valid choice." << endl;
cout << "Choose again." << endl;
cin >> choice;
break;
}
}
}
void inputDist(CDistance distList[], int size)
{
int dist = 0;
for (int i = 0; i < 6; i++)
{
cin >> distList[i];
}
}
//CDistance printAndAdd(const CDistance distList[], int size);
int main()
{
CDistance d1, d2(0, 0, 0, 0);
CDistance distList[5];
d1.setDistt();
d1.printDistt();
d1.menu(d2);
inputDist(distList, 0);
_getch();
return 0;
}
これはまさにそのことです...演算子は定義されていないので、 'cin'から' CDistance'を読むことができます。 – immibis
** conio.h **の使用を中止してください。 _C++標準ライブラリの一部ではありません。 – Destructor
これは、あなたが投稿しているもの以外のコンパイルエラーを全面的に持っています。それらを最初に修正し、_then_、まだ助けが必要な場合は、もう一度聞くことができます。 –