让编译器只执行预处理,不进行后面的编译和链接,直接输出预处理后的结果# 1 "rational.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "rational.cpp"
# 1 "rational.h" 1
# 10 "rational.h"
# 1 "/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/iostream" 1 3
# 36 "/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/iostream" 3
# 37 "/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/iostream" 3
# 1 "/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/x86_64-pc-cygwin/bits/c++config.h" 1 3
# 229 "/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/x86_64-pc-cygwin/bits/c++config.h" 3
# 229 "/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/x86_64-pc-cygwin/bits/c++config.h" 3
namespace std
{
typedef long unsigned int size_t;
typedef long int ptrdiff_t;
.......
extern wostream wcerr;
extern wostream wclog;
static ios_base::Init __ioinit;
}
# 11 "rational.h" 2
# 12 "rational.h"
namespace myMath
{
class Rational
{
public:
Rational(int num, int denom);
Rational operator+(Rational rhs);
Rational operator-(Rational rhs);
Rational operator*(Rational rhs);
Rational operator/(Rational rhs);
private:
void normalize();
int numerator;
int denominator;
friend std::ostream& operator<<(std::ostream& os, Rational f);
};
}
# 2 "rational.cpp" 2
# 1 "/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/stdlib.h" 1 3
# 36 "/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/stdlib.h" 3
# 1 "/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/cstdlib" 1 3
# 39 "/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/cstdlib" 3
# 40 "/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/cstdlib" 3
# 37 "/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/stdlib.h" 2 3
# 38 "/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/stdlib.h" 3
using std::abort;
using std::atexit;
using std::exit;
using std::at_quick_exit;
using std::quick_exit;
using std::div_t;
using std::ldiv_t;
using std::abs;
using std::atof;
using std::atoi;
using std::atol;
using std::bsearch;
using std::calloc;
using std::div;
using std::free;
using std::getenv;
using std::labs;
using std::ldiv;
using std::malloc;
using std::mblen;
using std::mbstowcs;
using std::mbtowc;
using std::qsort;
using std::rand;
using std::realloc;
using std::srand;
using std::strtod;
using std::strtol;
using std::strtoul;
using std::system;
using std::wcstombs;
using std::wctomb;
# 4 "rational.cpp" 2
# 5 "rational.cpp"
namespace myMath
{
Rational::Rational(int num, int denom)
{
numerator = num;
denominator = denom;
normalize();
}
void Rational::normalize()
{
if( denominator < 0 )
{
numerator = -numerator;
denominator = -denominator;
}
int a = abs(numerator);
int b = abs(denominator);
while( b > 0 )
{
int t = a % b;
a = b;
b = t;
}
numerator /= a;
denominator /= a;
}
Rational Rational::operator+(Rational rhs)
{
int a = numerator;
int b = denominator;
int c = rhs.numerator;
int d = rhs.denominator;
int e = a*b + c*d;
int f = b*d;
return Rational(e, f);
}
Rational Rational::operator-(Rational rhs)
{
rhs.numerator = -rhs.numerator;
return operator+(rhs);
}
Rational Rational::operator*(Rational rhs)
{
int a = numerator;
int b = denominator;
int c = rhs.numerator;
int d = rhs.denominator;
int e = a*c;
int f = b*d;
return Rational(e, f);
}
Rational Rational::operator/(Rational rhs)
{
int t = rhs.numerator;
rhs.numerator = rhs.denominator;
rhs.denominator = t;
return operator*(rhs);
}
std::ostream& operator<<(std::ostream& os, Rational f)
{
os << f.numerator << "/" << f.denominator;
return os;
}
}
|