2012-09-23 2 views
-1
#include <iostream> 
#include <iomanip> 
using namespace std; 

int main() // print to console: 3.0*5.0=15.00 
{ 
    double a; 
    double b; 
    a =(3.0); 
    b =(5.0); 
    cout << " " << fixed << setprecision (1) << a << "\n" << endl; 
    cout << "* " << b << "\n" << endl; 
    cout << "------" << endl; 
    cout << fixed << setprecision (2) << a*b << "\n" << endl; 
    return 0; 
} 

int calculate() // print to console: (7.1*8.3)-2.2=56.73 
{ 
    double a; 
    double b; 
    double c; 
    a = (7.1); 
    b = (8.3); 
    c = (2.2); 
    cout << " " << fixed << setprecision (1) << a << "\n" << endl; 
    cout << "* " << b << "\n" << endl; 
    cout << "- " << c << "\n" << endl; 
    cout << "------" << endl; 
    cout << setprecision(2) << (a*b)-c << "\n" << endl; 
    return (a*b)-c; 
} 

int calculation() // print to console: 3.2/(6.1*5.0)=0.10 
{ 
    double a; 
    double b; 
    double c; 
    a=(3.2); 
    b=(6.1); 
    c=(5.0); 
    cout << " " << fixed << setprecision (1) << a << "\n" << endl; 
    cout << b << "*" << c << endl; 
    cout << "------" << endl; 
    cout << setprecision(2) << a/(b*c) << "\n" << endl; 

    system("PAUSE"); 
    return a/(b*c); 
} 

이 오류가 발생하지 않았습니다. 나는 C++을 처음 사용하기 때문에 약간의 방향이 좋습니다! 이 코드를 깜박이지 않고 인쇄하려면 어떻게해야합니까? 고맙습니다!어떻게 작동합니까? 이해할 수없는 2 가지 중대한 오류가 있습니까?

출력 : 1> LINK : 오류 LNK2001 : 확인되지 않은 외부 기호 _mainCRTStartup 1> 치명적인 오류 LNK1120 : 1 개 확인되지 않은 외부

+0

하위 시스템 설정 값은 무엇입니까? – Borgleader

+0

나는 그것이 무엇인지 모른다. –

+0

프로젝트 -> 속성 -> 링커 -> 시스템 -> 서브 시스템. 그 가치는 무엇입니까? – Borgleader

답변

0

대부분의 아마 [통화 당] 파일이 프로젝트의 소스 파일의 일부가 아니며, 따라서 컴파일되지 않으며 해당 오브젝트 코드 파일이 링크되지 않습니다.

오류를 재현 :

 
[d:\dev\test] 
> type nul >bah.rc 

[d:\dev\test] 
> rc /nologo bah.rc 

[d:\dev\test] 
> dir /b *.res 
bah.res 

[d:\dev\test] 
> link /nologo bah.res /out:bah.exe /entry:mainCRTStartup /subsystem:console /machine:x86 
LINK : error LNK2001: unresolved external symbol _mainCRTStartup 
bah.exe : fatal error LNK1120: 1 unresolved externals 

[d:\dev\test] 
> _ 

해결 방법 : 비주얼 스튜디오 프로젝트에 파일을 추가 (그리고 솔루션 파일).


코드에 대해서는,이 시도 :

#include <iostream>   // std::wcout, std::endl, std::fixed 
#include <iomanip>   // std::setprecision 
#include <string>   // std::wstring 
using namespace std; 

void display(char const expression[], double const result) 
{ 
    wcout << expression << " = " << result << endl; 
} 

#define DISPLAY(expr) display(#expr, expr) 

int main() 
{ 
    wcout << fixed << setprecision(1); 
    DISPLAY(3.0*5.0); 
    DISPLAY((7.1*8.3)-2.2); 
    DISPLAY(3.2/(6.1*5.0)); 
} 

나는 일반적으로 단지 일반적인 숙제 문제에 대한 해결책을 제시하지 않을 것입니다.

그러나 시도한 해결책은 잘못된 (학습에 좋지 않은) 방향으로 향하는 것 같습니다.

0

확인/업데이트이 변수 :

enter image description here

이 설정은 "기본"함수의 이름을 제어합니다. 즉,이 설정은 연결 프로세스를 시작할 때 링커가 어떤 이름을 찾아야하는지 링커에게 알려줍니다. 약 8 개의 서브 시스템이 있고 각각에는 "메인"이 있습니다.

+0

오류 메시지 누락 된'main'보다 약간 더 미묘합니다.런타임 라이브러리에 누락 된 엔트리 포인트입니다. 발생할 수있는 하나의 (그리고 아마도 유일한) 방법에 대한 내 대답을 참조하십시오. –

+0

당신이 옳을 수 있습니다. –

관련 문제