У меня все по большей части готово. Запись всего в файл — это то, что меня действительно затруднило. Я открываю файл, чтобы прочитать входные данные в основной функции, я думал о передаче переменной ofstream в функции моего класса, но понял, что это не сработает, поскольку некоторые из них являются бинарными операторами и не принимают третий аргумент.
Вот мой код:
Файл заголовка:
Код: Выделить всё
#include
#include
#include
using namespace std;
class LargeIntegerNumber
{
public:
//Default constructor
LargeIntegerNumber();
//Set Array calls getNumber and convertNumber
void setArray(ostream& out);
//Obtains user input for string
void getNumber(ostream& out);
//Parses string into array
void convertNumber(LargeIntegerNumber array1);
//Compares the two numbers and displays result
void comparison(LargeIntegerNumber array1, LargeIntegerNumber array2, ostream& out);
friend void operator *(LargeIntegerNumber array1, LargeIntegerNumber array2);
friend void operator -(LargeIntegerNumber array1, LargeIntegerNumber array2);
friend void operator +(LargeIntegerNumber array1, LargeIntegerNumber array2);
friend istream& operator >>(istream& cin, LargeIntegerNumber& array1);
private:
int array[20];
string number;
int numSize;
int arrayNegative;
};
Код: Выделить всё
istream& operator >>(istream& cin, LargeIntegerNumber& array1)
{
//Prompt user to input string and retrieve result
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/24965467/c-writing-to-a-file-in-and-out-of-class-functions[/url]
Мобильная версия