complex - STL C++

operator>>()

Declaration

template <class X, class XCharType, class XTraits>
basic_istream<XCharType, XTraits>& operator>>(basic_istream<XCharType, XTraits>& qrInStream,
                                              complex<X>& qrZ);

Description

This friend function is the overloaded extraction operator for the complex class. For complex numbers, three styles of input are allowed: (x,y), (x), x.

Header Include

#include <complex>

Example

#include <complex>
#include <iostream>

int main()
{
	using namespace std;

	// Request input three times for complex numbers
	complex<double> qZ;
	for (int i = 0; i < 3; ++i) {
		cout << "Input a complex number: ";
		cin >> qZ;
		cout << "The number is " << qZ << endl;
	}

	// Keep the window open
	cin.clear();
	cin.ignore(0xFFFFFFFF, '\n');
	cin.get();
	return 0;
}

Output

operator>>() Output
 

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