fork download
  1. #include "VectorCpx.h"
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. fstream file("outVec.txt", ios::out);
  6.  
  7. void outVec(const VectorCpx& v){
  8. file << "Size: " << v.size() << ", Capacity: " << v.capacity() << endl;
  9. file << v;
  10. }
  11.  
  12. int main(){
  13. VectorCpx v1;
  14. VectorCpx v2(5, Complex(1.234, 5.678));
  15. VectorCpx v3 = v2;
  16. file << "--------- A --------" << endl;
  17. file << v1 << v2 << v3;
  18.  
  19. v2[2].real(9.87);
  20. v3[-1].real(0);
  21. v3[100].imag(999);
  22. file << "--------- B --------" << endl;
  23. outVec(v1); outVec(v2); outVec(v3);
  24. file << "v2*v3=" << v2 * v3 << endl;
  25.  
  26. v1.resize(10);
  27. v2.resize(8, Complex(0.1, 0.5));
  28. v3.resize(3);
  29. file << "--------- C --------" << endl;
  30. outVec(v1); outVec(v2); outVec(v3);
  31. file << "v2*v3=" << v2 * v3 << endl;
  32.  
  33. v1.resize(2);
  34. v3 = v1;
  35. file << "--------- D --------" << endl;
  36. outVec(v1); outVec(v2); outVec(v3);
  37.  
  38. v3[0] = v2[0];
  39. v3[1] = v2[2];
  40. v2.push_back(Complex(0.8051, 0.9801));
  41. v3.push_back(Complex(0.5566, 0.9527)); //這裡很謎,如果寫v3.push_back(Complex(0.5566, 0.9527)).push_back(Complex(0.2, 0.3))會讀不到後面那個,拆開卻沒事
  42. v3.push_back(Complex(0.2, 0.3));
  43. file << "--------- E --------" << endl;
  44. outVec(v1); outVec(v2); outVec(v3);
  45. file << "v2*v3=" << v2 * v3 << endl;
  46.  
  47. v1 = v3 * Complex(2.0);
  48. v2 = Complex(3.0, 4.0) * v3;
  49. file << "--------- F --------" << endl;
  50. outVec(v1); outVec(v2); outVec(v3);
  51.  
  52. file.close();
  53. }
  54.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:23: fatal error: VectorCpx.h: No such file or directory
compilation terminated.
stdout
Standard output is empty