complex - STL C++

real()

Declaration

X real(const complex<X>& kqrZ);

Description

This is the friend function real() for complex numbers. It returns the real part of the complex number kqrZ. The formula for the real part of a complex number z = x + iy, for real numbers x and y is

real(z) = x.

Header Include

#include <complex>

Example

#include <complex>
#include <iostream>

int main()
{
	using namespace std;

	// Create a complex number and get its real part
	complex<double> qZ(2.0, 4.0);
	cout << "Complex Number : "<< qZ << endl;
	cout << "The real part is "<< real(qZ) << endl;

	// Keep the window open
	cin.get();
	return 0;
}

Output

real() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.