小编osm*_*an 的帖子

C ++ ifstream和ofstream重载运算符从文件中读取

大家好,我正在尝试重载ifstream和ofstream,但没有成功。

头文件:

#include <iostream>
#include <fstream>

using namespace std;

class Complex
{
    private:
        double real;
        double imaginary;
    public:
        //constructors
        Complex();
        Complex(double newreal, double newimaginary);
        ~Complex();
        //setter
        void setReal(double newreal);
        void setImaginary(double newimaginary);
        //getter
        double getReal();
        double getImaginary();
        //print
        void print();
        //methods
        Complex conjugate();
        Complex add(Complex c2);
        Complex subtraction(Complex c2);
        Complex division(Complex c2);
        Complex multiplication(Complex c2);

friend ifstream& operator >> (ifstream& in, Complex &c1)
{

    in >> c1;

    return in;
}

};
Run Code Online (Sandbox Code Playgroud)

测试文件:

#include <iostream>
#include <fstream>
#include <string>
#include "Complex2.h" …
Run Code Online (Sandbox Code Playgroud)

c++ overloading operator-keyword

0
推荐指数
1
解决办法
5194
查看次数

标签 统计

c++ ×1

operator-keyword ×1

overloading ×1