Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7935591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:58:11+00:00 2026-06-03T21:58:11+00:00

I did a program that took command line arguements to run it. I am

  • 0

I did a program that took command line arguements to run it. I am now trying to do a menu drive program as part of its “improvement.” I used,

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

in the original where the arguements were:

char * startCity = argv[1];
char * endCity = argv[2];
in.open(argv[3],ios::in); //<----file name went here

Here is what I did now and I know it is incorrect:

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;

Since all of my program is based on char * argv[] How can I convert those into strings OR how can I assign variables to the arguements in order to read them in?

I appreciate all the answers but they seem to be going in the direction I am trying to get away from. The OLD program used command line arguements. How can I do this:

string StartCity = char * argv[1];
string EndCity = char * agrv[2];
string filename = in.open(argv[3],ios::in);

That is what I am trying to do. I am sorry if I did not make myself clear.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:58:13+00:00Added an answer on June 3, 2026 at 9:58 pm

    This might help.

    int main (int argc, char ** argv)
    {
              std::vector<std::string> params(argv, argv + argc);       
              //Now you can use the command line arguments params[0], params[1] ... 
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I did a program that reads rss news feeds. Its not working for some
In a program that I'm trying to write now I take two columns of
I have a (java) program that prints a line of hex numbers to stdout
I have a program that reads a huge text file (line by line) and
I have a program (that I did not write) which is not designed to
I am working on a C program that I did not write and integrating
I have a program that can generate video in real time. Now I would
I made a Java program that did some basic math for kids in primary.
I did a program that tells you your zodiacal sign. It compiles, but when
In this article , the writer asserts: ...the program did show that the template

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.