C++ macro expansion output problem?
淡淡烟草味
淡淡烟草味 2017-05-16 13:30:56
0
1
773
#include <stdio.h>
#include <cmath>
#include <iostream>
using namespace std;
#define pi 3.1415926;
//const double pi=3.1415926;
int main(){
//    printf("%f",(atan2(-1,1)*180/pi));
    cout<< atan2(-1,1)*180/pi;// <<endl;
}

The program is as above. The output is normal under the above circumstances, but after slight modification, the following problems occur.

  1. The program reports an error when adding <<endl. Starting another cout<<endl can output normally.

  2. I tried adding brackets to <<endl, but still got an error.

  3. I tried to use printf to output, but found that it could not be output without adding n.

  4. Everything works fine when using const constants

I don’t understand why macros are not directly replaced? Why is there a problem?

淡淡烟草味
淡淡烟草味

reply all(1)
为情所困
#define pi 3.1415926;

There is an extra; semicolon

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template