Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,602 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 948 people online right now. Registration is fast and FREE... Join Now!




Accepting variable values from the command line

 
Reply to this topicStart new topic

Accepting variable values from the command line

Sn0wm4n
post 15 Jul, 2008 - 02:58 PM
Post #1


New D.I.C Head

*
Joined: 8 Jul, 2008
Posts: 11


My Contributions


I just found out how to use int main(int argc, char *argv[]) and I was wondering why it wouldn't work when I try to use argv[1] in my program. It says "C:\DOCUME~1\...\Desktop\cmd.exe. The NTVDMCPU has encountered an illegal instruction. CS:0de8 IP:0103 OP:63 6c 75 64 65." When I save it as a .exe file and try to run it. Any suggestions?

CODE
#include <iostream>
#include <cstdlib>

using namespace std;

int main(int argc, char *argv[])
{
cout << argv[0] << endl;
cout << argv[1] << endl;
if (argv[1] == "anything") {
             cout << "It WORKED!" << endl;}
system("PAUSE");
}


obviously, this is just something that will show the two values of argv[0] and argv[1] and will show "It WORKED!" only if the word right after the program name is "anything" in the command prompt.
User is offlineProfile CardPM

Go to the top of the page

lordms12
post 16 Jul, 2008 - 02:35 PM
Post #2


D.I.C Regular

Group Icon
Joined: 16 Feb, 2008
Posts: 312



Thanked 13 times

Dream Kudos: 225
My Contributions


yourProgramName try anything
Type this in .bat file, in cmd, in run command or anywhere you want it should work
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 02:10AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month