inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

홍정모의 따라하며 배우는 C++

3.9 비트 플래그, 비트 마스크 사용법 Bit flags, Bit masks

3.9 연습문제 기사

549

shoon723

작성한 질문수 1

1

#include <iostream>

#include <bitset>

int main()

{

using namespace std;

unsigned char option_viewed = 0x01;

unsigned char option_edited = 0x02;

unsigned char option_liked = 0x04;

unsigned char option_shared = 0x08;

unsigned char option_deleted = 0x80;

unsigned char my_article_flags = 0;

cout << "option_viewed " << bitset<8>(option_viewed) << endl;

cout << "option_edited " << bitset<8>(option_edited) << endl;

cout << "option_liked " << bitset<8>(option_liked) << endl;

cout << "option_shared " << bitset<8>(option_shared) << endl;

cout << "option_deleted " << bitset<8>(option_deleted) << '\n' << endl;

//view article

my_article_flags |= option_viewed;

cout << "option_viewed " << bitset<8>(my_article_flags) << endl;

//click like

my_article_flags ^= option_liked;

cout << "option_liked " << bitset<8>(my_article_flags) << endl;

//click like again

my_article_flags ^= option_liked;

cout << "option_liked " << bitset<8>(my_article_flags) << endl;

//delete

if (my_article_flags & option_viewed)

{

my_article_flags |= option_deleted;

}

cout << "option_deleted " << bitset<8>(my_article_flags) << endl;

return 0;

}

무슨 문제가 있는지 마지막 delete에서 build가 되지 않는 오류가 발생합니다. 이유가 무엇일까요?

c++

답변 3

1

Soobak

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

우선, 첨부해주신 코드를 제 환경에서 컴파일 후 실행해본 결과 정상적으로 동작합니다.

  • 결과 첨부
    image

     

또한, 문법 상으로도 특별한 문제점을 찾기가 어렵습니다.

따라서, 코드에 대한 추가적인 설명이나, 출력되는 오류 메시지의 전문을 첨부해주시면 제가 더 적절한 도움을 드릴 수 있을 것 같습니다.

만족스러운 답변을 드리지 못해 죄송합니다.

0

shoon723

아닙니다! 제 비주얼스튜디오나 컴퓨터에 문제가 있는 것 같네요. 친절하게 답변해주셔서 감사합니다!

0

shoon723

우선 build시 success가 되지 않습니다

Build started...

========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========

무시하고 디버그 후 실행시 deleted를 제외한 부분만 실행됩니다.

 

1

shoon723

중간에 줄바꿈이 되지 않은 것은 제가 삭제하고 수행해보아 그렇습니다. 그 외에는 위 코드에서 수정한 바 없습니다.

0

Soobak

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

우선, 첨부해주신
========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
메시지는, 빌드에 실패했음을 뜻하는 것이 아니며 최근 변경 사항이 없어 이미 최신 상태의 빌드로 잘 진행되었다는 것을 의미합니다.

또한, 이번에는 저도 Visual Studio 2022 컴파일러로 동일한 코드를 Release 모드, Debug 모드 모두에서 컴파일을 진행해보았는데 정상적으로 빌드가 진행되었습니다.

빌드를 진행한 코드는 아래와 같습니다.

#include <iostream>
#include <bitset>

using namespace std;

int main() {

  using namespace std;

  unsigned char option_viewed = 0x01;

  unsigned char option_edited = 0x02;

  unsigned char option_liked = 0x04;

  unsigned char option_shared = 0x08;

  unsigned char option_deleted = 0x80;

  unsigned char my_article_flags = 0;

  cout << "option_viewed " << bitset<8>(option_viewed) << endl;

  cout << "option_edited " << bitset<8>(option_edited) << endl;

  cout << "option_liked " << bitset<8>(option_liked) << endl;

  cout << "option_shared " << bitset<8>(option_shared) << endl;

  cout << "option_deleted " << bitset<8>(option_deleted) << '\n' << endl;

  //view article

  my_article_flags |= option_viewed;

  cout << "option_viewed " << bitset<8>(my_article_flags) << endl;

  //click like

  my_article_flags ^= option_liked;

  cout << "option_liked " << bitset<8>(my_article_flags) << endl;

  //click like again

  my_article_flags ^= option_liked;

  cout << "option_liked " << bitset<8>(my_article_flags) << endl;

  //delete

  if (my_article_flags & option_viewed)

  {

    my_article_flags |= option_deleted;

  }

  cout << "option_deleted " << bitset<8>(my_article_flags) << endl;

  return 0;

}
  • 실행 결과
    image



코드를 정말 꼼꼼히 살펴보았는데도, 질문자님께서 빌드에 실패할만한 이유를 찾지 못하겠습니다. 😭😭
메세지의 출력 결과도 빌드에 실패하였다는 것을 의미하지 않습니다.

혹시 추가적으로 제공해주실 만한 정보가 있다면 말씀해주시면 감사하겠습니다...
올바른 도움을 드리지 못해 진심으로 죄송합니다.

강의자료는 어디서 받을 수 있죠?

1

25

2

교재 있나요?

1

140

2

11:11 부근에 Something::temp와 Something::getValue의 앞에 &를 붙이는 이유가 뭔가요? (함수 이름은 포인터(주소)가 아닌가요?)

1

93

3

using namespace std; 선언 후에 std::를 하는 이유가 궁금합니다

1

103

2

cstr직접구현

0

117

3

BubbleSort

1

79

2

숙제 마지막 부분

1

80

2

강의와 똑같이 진행했는데 링킹 에러가 발생합니다.

1

96

2

수업할때 레퍼런스로 사용하는 도서는 어떤 도서인가요??

1

165

2

공변반환형 관련 문의 드립니다.

1

92

2

170강 유니크 포인터에대해 질문있습니다

1

82

1

섹션 5 퀴즈의 답이 이상합니다

1

85

2

이중포인터와 배열이 이해가 안됩니다.

1

159

2

5분 17~5분 34초 객체 잘림 질문

1

80

1

Resource.h 코드 알려주세요

1

74

1

char name[] 배열의 길이와 관련해 일부 궁금점이 생겨서 질문합니다

1

95

2

화면좌측 숫자 보이기

1

116

1

화면 좌측 숫자 보이기

0

68

1

처음 c++ 수강하려는데요. 비주얼스튜디오 2022 다운로드해서 설치하면 되는건가요??

1

139

3

46강 string 버퍼 질문입니다

1

82

2

프로그래머스 수열과 구간 쿼리 2 문제 질문입니다.

1

125

2

[] 범위 검사시 assert 사용 관련 질문

1

92

2

Lecture 클래스 멤버변수 명명 관련

0

93

2

프로그래머스의 대소문자 바꿔서 출력하기 문제를 푸는데요

0

75

1