• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

3.9 연습문제 기사

23.08.21 21:03 작성 조회수 329

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가 되지 않는 오류가 발생합니다. 이유가 무엇일까요?

답변 3

·

답변을 작성해보세요.

1

Soobak님의 프로필

Soobak

2023.08.22

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

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

  • 결과 첨부
    image

     

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

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

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

0

shoon723님의 프로필

shoon723

질문자

2023.08.23

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

0

shoon723님의 프로필

shoon723

질문자

2023.08.22

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

Build started...

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

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

 

shoon723님의 프로필

shoon723

질문자

2023.08.22

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

Soobak님의 프로필

Soobak

2023.08.22

안녕하세요, 답변 도우미 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



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

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