fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <complex>
  4.  
  5. int main()
  6. {
  7. std::istringstream buf("67 - 23i");
  8.  
  9. char minus, i;
  10. double re, im;
  11. buf >> re >> minus >> im >> i;
  12. if(!buf || minus != '-' || i != 'i')
  13. std::cout << "Parse error\n";
  14. else
  15. std::cout << std::complex<double>(re, im) << '\n';
  16. }
  17.  
Success #stdin #stdout 0.02s 2816KB
stdin
Standard input is empty
stdout
(67,23)