stl的complex(二)

cin.ignore(int size, int delim)是读取,然后删掉,直到碰到delim字符

cin.peek()是获取输入流的第一个字符,但是pos没有移动

#include <iostream>
#include <complex>
#include <cstdlib>
#include <limits>
#include <cstdio>

using namespace std;

int main()
{
    complex<long double> c1, c2;

	while (cin.peek() != EOF) {
		cout << "complex number c1: ";
		cin >> c1;

		if (!cin) {
			cerr << "input error" << endl;
			return EXIT_FAILURE;
		}

		cout << "complex number c2:";
		cin >> c2;
		if (!cin) {
			cerr << "input error" << endl;
			return EXIT_FAILURE;
		}

		if (c1 == c2) {
			cout << "c1 and c2 are equal !" << endl;
		}

		cout << "c1 raised to the c2: " << pow(c1, c2) << endl << endl;

		cin.ignore(numeric_limits<int>::max(), '\n');  //忽略该行
	}
}


你可能感兴趣的:(stl的complex(二))