티스토리 뷰

#include <iostream>
#include <fstream>

using namespace std;

class Point
{
	private:
	double m_x, m_y, m_z;
	
	public:
	Point(double x = 0.0, double y = 0.0, double z = 0.0)
		: m_x(x), m_y(y), m_z(z)
	{}
	
	double getX() { return m_x; }
	double getY() { return m_y; }
	double getZ() { return m_z; }
	
	// void print()
	// {
	// 	cout << m_x << " " << m_y << " " << m_z << endl;
	// }
	
	friend std::ostream& operator << (std::ostream &out, const Point &point)
	{
		out << point.m_x << " " << point.m_y << " " << point.m_z;
		
		return out;
	}
	
	friend std::istream& operator >> (std::istream &in, Point &point)
	{
		in >> point.m_x >> point.m_y >> point.m_z;
		
		return in;
	}
};


int main()
{
	ofstream of("oust.txt");
	
	//Point p1(0.0, 0.1, 0.2), p2(3.4, 1.5, 2.0);
	Point p1, p2;
	
	cin >> p1 >> p2;
	
	cout << p1 << " " << p2 << endl;
	of << p1 << " " << p2 << endl;
	
	of.close();
	
	return 0;
}

// 1.0 4.5 3.2
// 5.2 1.4 5.3
// 1 4.5 3.2 5.2 1.4 5.3
1 4.5 3.2 5.2 1.4 5.3

//ouss.txt

 

 

#include <iostream>
#include <fstream>

using namespace std;

class Cents
{
	private:
	int m_cents;
	
	public:
	Cents(int cents = 0) { m_cents = cents; }
	int getCents() const { return m_cents; }
	int &getCents() { return m_cents; }
	
	Cents operator - () const
	{
		return Cents(-m_cents);
	}
	
	friend std::ostream& operator << (std::ostream &out, const Cents &cents)
	{
		out << cents.m_cents;
		
		return out;
	}
};


int main()
{
	Cents cents1(6);
	Cents cents2(0);
	
	cout << cents1 << endl;
	cout << -cents1 << endl;
	cout << -Cents(-10) << endl;
	
	return 0;
}

// 6
// -6
// 10

 

not operator

	bool operator ! () const
	{
		return (m_cents == 0) ? true : false;
	}
	cout << !cents1 << " " << !cents2 << endl;
    
    // 0 1
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함