2014-02-21 3 views
-2

프로그램을 파일에 작성한 다음 실행하는 C++ 프로그램을 만들고 싶습니다. 목표는 임의의 숫자 생성기 또는 이와 유사한 것을 만들고, 각각을 테스트하고 알고리즘의 "자연 선택"과 같은 것을 수행하여 더 나은 최종 생성기를 얻습니다 (그리고 프로세스를 반복 할 수도 있음).다른 C++ 프로그램을 실행하는 C++ 프로그램

나는 AI 부분에 관심이 없다. 난 그냥 다른 C + + 프로그램을 실행하는 C + + 프로그램이 가능하고 이것을 달성하는 방법인지 알고 싶습니다.

감사합니다.

+0

http://en.cppreference.com/w/cpp/utility/program/system – willll

답변

1
int result = system("another_program"); 

여기는 reference입니다.

+0

확인을하지만, 윈도우 방법이 이러는거야? – ioanD

+0

http://stackoverflow.com/questions/6783256/run-c-program-in-c-program?rq=1 참조 – OMGtechy

0

당신은 당신이 필요로하는 다른 모든 프로그램 시작 CreateProcess WinAPI를 사용할 수 있습니다 :

STARTUPINFO si; 
PROCESS_INFORMATION pi; 

ZeroMemory(&si, sizeof(si)); 
si.cb = sizeof(si); 
ZeroMemory(&pi, sizeof(pi)); 
wchar_t command[MAX_PATH]; 
swprintf_s(command, L"path to whatever program you need"); 

// Start the child process. 
if(!CreateProcess(NULL, // No module name (use command line) 
    command,  // Command line 
    NULL,   // Process handle not inheritable 
    NULL,   // Thread handle not inheritable 
    FALSE,   // Set handle inheritance to FALSE 
    0,    // No creation flags 
    NULL,   // Use parent's environment block 
    NULL,   // Use parent's starting directory 
    &si,   // Pointer to STARTUPINFO structure 
    &pi)   // Pointer to PROCESS_INFORMATION structure 
) 
{ 
    MessageBox(NULL, L"Could not start program", L"Error", MB_OK | MB_ICONERROR); 
} 
관련 문제