How to use complex number “i” in C++

后端 未结 6 983
暗喜
暗喜 2021-02-06 08:19

I am coding a simple DFT algorithm now and I want to use the complex number i in complex exponential. I saw somebody use #include and #include&

6条回答
  •  萌比男神i
    2021-02-06 09:10

    Another way is to use std::literals::complex_literals::operator""i after C++14:

    #include 
    #include 
    
    int main() {
        using namespace std::complex_literals;
        auto c = 1.0 + 3.0i;
        std::cout << "c = " << c << '\n';
    }
    

    Output:

    c = (1,3)
    

提交回复
热议问题