2015-01-30 2 views
0

Microsoft Visual Studio 12에서 C++을 사용하고 있습니다. 명령 줄 인수를 전달하고 싶습니다. MSVS의 Project/Properties/Debugging/Command Arguments 필드에 나열하려고 시도했지만 CLIArgsMadeEasy 추가 기능을 사용해 보았지만 작동하지 않습니다. argc는 항상 1입니다. 물론 argv [0]은 app 경로입니다. 예 : 나는 세 가지 인수와 함께 시작하고 싶은 fred.exe의 프로그램 제공 : A, B, C 즉MSVS 12, C++, 명령 인수가 작동하지 않습니다.

fred.exe ABC

I의 cmd를 윈도우 라인의 동등한 정확히으로 제공되는 편집 상자에 인수를 지정

ABC

(MSVS 표준 또는 CLIArgsMadeEasy)하지만 난 실행할 때이 전달되지 않습니다 위에서 설명한 방법 중 하나를 사용하여. 내 비주얼 스튜디오에서이 프로그램을 시도

+0

VS에서 디버그 모드로 프로그램을 실행하고 있습니까? – mclaassen

+0

프로젝트 속성 → 디버깅 → 명령 인수 –

+0

1) 예, VS에서 디버그 모드를 실행 중입니다. 디버깅을 위해 작동하지 않는 릴리스를 빌드하고 실행했습니다. X64. 2) 내 게시물 당, 나는 프로젝트 속성 → 디버깅 → 명령 인수를 시도했다 (그리고 그 후 CLIArgsMadeEasy를 추가했지만 그 중 도움이되지 않았다) – user3288226

답변

1

#include <iostream> // for standard I/O 
#include <string> // for strings 
#include <iomanip> // for controlling float print precision 
#include <sstream> // string to number conversion 
#include <math.h> 

using namespace std; 

int main(int argc, char *argv[]) 
{ 

... 그리고 그것은 작동 :

코드는

#include <iostream> // for standard I/O 
 
#include <string> // for strings 
 
#include <iomanip> // for controlling float print precision 
 
#include <sstream> // string to number conversion 
 
#include <math.h> 
 

 
using namespace std; 
 

 
int main(int argc, char *argv[]) 
 
{ 
 
\t for(int i = 1; i < argc; i++) 
 
\t { 
 
\t \t cout << i << ":" << argv[i] << endl; 
 
\t } 
 
\t return 0; 
 
}

enter image description here

관련 문제