c++ 오류 해결 좀

c++ 오류 해결 좀

작성일 2023.10.02댓글 2건
    게시물 수정 , 삭제는 로그인 필요







두 수를 비교해서 최댓값과 최솟값을 구하는 코드를 짰는데, 자꾸 이런 오류가 뜨네요.. 어떻게 해결해야 할까요..?


#c++ 오류 #c++ 오류 처리 #c++ 오류 찾기 #c++ 오류 무시 #c++ 오류 해결 #c++ scanf 오류 #dev c++ 오류 #dev c++ 오류창 안뜸 #마이크로소프트 visual c++ 오류 #런타임 c++ 오류

profile_image 익명 작성일 -

max라는 함수를 만드는데 max라는 함수를 불러오네요? 제가 생각하기에는 if(a>=b) max1=a

else max1=b

이렇게 하시는게 더 나을겁니다.

아니면 int max1=(a>=b)?a:b;

이런식도 괜찮고요.

profile_image 익명 작성일 -

#include <algorithm> int max(int a, int b) { const int& max1 = std::max({ a, b }); std::cout << "max : " << max1 << std::endl; return 0; }

일단 첫번째 문제점

max, min, cout, endl은 namespace std 소속입니다.

using namespace std;가 없기 때문에 소속을 붙여서 사용해야 합니다.

두번째 문제점

std::max(a, b);와 같은 형태는 algorithm을 include하지 않고 사용 가능합니다.

하지만 std::max({a, b});와 같은 형태는 algorithm을 include해야만 사용 가능합니다.

// mathlib.h #pragma once namespace mathlib { int max(int, int); int min(int, int); int a = 30, b = 70; };
// mathlib.cpp #include "mathlib.h" #include <iostream> #include <algorithm> namespace mathlib { using std::cout, std::endl; int max(int a, int b) { using std::max; const int& max1 = max({ a, b }); cout << "max : " << max1 << endl; return 0; } int min(int a, int b) { using std::min; const int& min1 = min({ a, b }); cout << "min : " << min1 << endl; return 0; } };
// main.cpp #include "mathlib.h" int main() { mathlib::max(mathlib::a, mathlib::b); mathlib::min(mathlib::a, mathlib::b); using namespace mathlib; max(a, b); min(a, b); return 0; }
max : 70 min : 30 max : 70 min : 30
#pragma once namespace std::mathlib { int max(int, int); int min(int, int); int a = 30, b = 70; }; #include <iostream> #include <algorithm> namespace std::mathlib { int max(int a, int b) { using std::max; const int& max1 = max({ a, b }); cout << "max : " << max1 << endl; return 0; } int min(int a, int b) { using std::min; const int& min1 = min({ a, b }); cout << "min : " << min1 << endl; return 0; } }; int main() { std::mathlib::max(std::mathlib::a, std::mathlib::b); std::mathlib::min(std::mathlib::a, std::mathlib::b); using namespace std; mathlib::max(mathlib::a, mathlib::b); mathlib::min(mathlib::a, mathlib::b); using namespace mathlib; max(a, b); min(a, b); return 0; }

Microsoft Visual C++오류 해결 방법[30]

Microsoft Visual C++Runtime Libray Buffer overrun detected! program: C:\Program Files\lnternet Explore... 이 오류 해결 방법좀 자세하게 알려주세요.내공 30. 버퍼 오버런"(buffer overrun)은...

비주얼 C++ 오류 해결 좀..

... 어떻게 해결하죠?ㅡㅜ.. 검색만 하고나면 이런거 뜨면서 창이 꺼져버려요..ㅜㅠ.. 꼭 도와주세요..ㅡㅜ.. 이건 비쥬얼 C++의 문제가 아니라.. 인터넷 익스플로러의 오류입니...

C++ 오류 해결좀

... 123213.exe - 1 error(s), 2 warning(s) 났는데요 에러 해결좀 ㅜㅜ 오류 부분을 지적해 드리면.. 1. double sum = 2.7; 에서 ;가 빠졌습니다. c...

Visual C++ Runtime Library 오류해결좀

Microsoft Visual C++ Runtime Library 오류해결좀. 한동안 뜨길래 신경도 안쓰고잇다가 갑작스럽게 이 오류뜨면서 컴터가 지절로 재부팅이되더군요... 인터넷 찾아보니 머 설정하고...

C++ Runtime Library 오류해결좀.

... 어떻게해야되나요 ㅠㅠ 해결좀요 . 질문 주신 Microsoft Visual C++ Runtime Library 오류는 컴퓨터에 설치된 C:\Program Files응용 프로그램과 인터넷 그리고 프로그램 들 끼리의...