Using cin for input complex number in C++11 -
#include <iostream> #include <complex> using namespace std; int main(){ complex<double> p; cin >> p.real() >> p.imag(); }
in g++4.7.2 works successfully, in c++11 failed compile. why?
it gives me following error message:
prog.cpp: in function ‘int main()’: prog.cpp:7:19: error: no match ‘operator>>’ in ‘std::cin >> p.std::complex<double>::real()’
full version: http://ideone.com/m3bhvr
you can simpler this:
cin >> p;
format must be: (real,imag) (see: here)
or can following:
double real, imag; cin >> real >> imag; complex<double> p(real, imag);
Comments
Post a Comment