integer
을 double
변수에 할당했지만 cout
은 double 변수를 int
으로 인쇄합니다. double
이 아닙니다. 코드에 cout << showpoint;
을 입력하면 출력 할 때 십진수 값을 볼 수 있습니다. 첫 번째 경우에 왜 그렇게됩니까? 여기에 코드가 있습니다.소수점 이하의 숫자를 건너 뛰는 cout
#include <iostream>
using namespace std;
template <class T>
T sum(T a,T b)
{
T retval;
retval=a+b;
return retval;
}
int main()
{
double a,x;
float y,v=4.66;
int z(3);
x=z;
y=(double)z;
a=sum(5,6);
//cout << showpoint;
cout<<"The value of a is : "<<a<<endl;
cout<<"The value of x is : "<<x<<endl;
cout<<"The value of y is : "<<y<<endl;
}
제 경우의 출력은 두 번째 경우 cout<<showpoint
를 활성화 한 후
The value of a is : 11
The value of x is : 3
The value of y is : 3
출력이다 소수점 형식에만 소수점으로 표시되는 부동 기본적
The value of a is : 11.0000
The value of x is : 3.00000
The value of y is : 3.00000
setprecision가 없으므로 질문을 편집했습니다. – blitz
무엇이'showpoint'입니까? – Raxvan
@Raxvan : 답변을 얻을 수있는 링크는 다음과 같습니다. http://faculty.cs.niu.edu/~mcmahon/CS241/c241man/node83.html – blitz