• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

fixed 관련 질문이 있습니다

23.05.28 14:24 작성 조회수 217

2

#include <iostream>
#include <iomanip>
using namespace std;


int main()
{
	float x = 79;

	cout << showpoint << fixed << x << endl;
	cout << noshowpoint << x << endl;
}

showpoint를 쓰다가 noshowpoint 조정자를 쓰면 리셋돼서 소수점이 다시 출력되지 않는 것처럼 fixed도 리셋할 수 있는 방법이 있나요?

답변 2

·

답변을 작성해보세요.

2

Soobak님의 프로필

Soobak

2023.05.28

안녕하세요, 답변 도우미 Soobak 입니다.

fixed 스트림 조정자를 초기화하는 방법 중 하나는 std::cout.unsetf() 을 통하여 상태 조정자를 초기화해주는 것입니다.
std::cout.unsetf(std::ios_base::fixed); 으로 초기화 해주시면 됩니다.

사용 예시 코드와 std::cout.unsetf() 관련 문서 링크를 첨부드립니다.

 

  • 예시코드

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    float x = 79;

    cout << showpoint << fixed << x << endl;  // fixed 조정자 사용
    cout.unsetf(ios_base::fixed); // fixed 조정자 초기화
    cout << noshowpoint << x << endl;
   
    return 0;
}

 

1

chaerynate님의 프로필

chaerynate

질문자

2023.05.28

감사합니다!!