コマンドライン引数を使って実行するプログラムを実行しました。私は今、 "改善"の一環としてメニュードライブプログラムをしようとしています。コマンドライン引数のプログラムをメニュー駆動型プログラムに変換する
char * startCity = argv[1];
char * endCity = argv[2];
in.open(argv[3],ios::in); //<----file name went here
ここで私は今何をしたかと私はそれが間違っている知っている:私のプログラムのすべて以来
int main(int argc, char * argv[]){
int menuChoice;
string startCity;
string endCity;
string fileName;
ifstream in;
cout<<"Welcome to J.A.C. P2\n"
"\n"
"This program will find the shortest path\n"
"from One city to all other cities if there\n"
"is a connecting node, find the shortest path\n"
"between two cities or find the shortest\n"
"between three or more cities.\n"<<endl;
cout<<"Please make a choice of what you would like to do:\n"<<endl;
cout<<" 1------> Shortest Path between 2 cities.\n"
" 2------> Shortest Path between 3 or more cities.\n"
" 3------> Shortest Path from 1 city to all.\n"
" 9------> Take your ball and go home!\n"<<endl;
cout<<"Waiting on you: "; cin>>menuChoice;
switch (menuChoice) {
case 1:
cout<<"Enter the starting city: ";
cin>>StartCity;
cout<<"\nEnter the ending city: ";
cin>>EndCity;
cout<<"\nEnter the name of the file: ";
cin>> fileName;
break;
私はarguementsがいたところ、元の中
int main(int argc, char * argv[])
は、使用しましたchar * argv []どのように文字列に変換できますか?またはそれらを読み込むためにどのように変数を代入することができますか?
私はすべての答えに感謝しますが、私は離れようとしている方向に向かっているようです。 OLDプログラムはコマンドライン引数を使用していました。どうすればいいですか:
string StartCity = char * argv[1];
string EndCity = char * agrv[2];
string filename = in.open(argv[3],ios::in);
これは私がやろうとしていることです。私が自分自身を明確にしなかった場合、私は残念です。
'string s = argv [0];'これは引数の変換の意味ですか? – chris
私はOPが他の方法を望んでいると思います。 'char * = sting s' – gardian06
@chrisいいえ、元の質問を編集しましたが、実際には私はやってみたいと思っています。 –