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

  • Home
  • SEARCH
  • 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 6385293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:52:52+00:00 2026-05-25T02:52:52+00:00

Many of my programs take in command-line arguments, one example is as follows: a.out

  • 0

Many of my programs take in command-line arguments, one example is as follows:

a.out [file-name] [col#] [seed]

Then if I want to use the arguments, I have nice, easy-to-use functions such as:

atof(argv[..]) and atoi(argv[..])

I was wondering if such easy/simple functions exist for C++. I tried to simply do this:

cin >> col_num >> seed;

But that doesn’t work… It waits for an input (not command-line) and then outputs it…

Thanks

  • 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-05-25T02:52:53+00:00Added an answer on May 25, 2026 at 2:52 am

    Solution 1:
    You can use lexical_cast in place of atoi

    int x = boost::lexical_cast<int>("12345"); 
    

    Use boost::lexical_cast in try-catch block though. It throws boost::bad_lexical_cast when the cast is invalid.

    Solution 2:
    If you are not using Boost and need a standard C++ solution you can use streams.

    std::string hello("123"); 
    std::stringstream str(hello); 
    int x;  
    str >> x;  
    if (!str) 
    {      
      // The conversion failed.      
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see so many programs take command-line arguments with flags, for example gcc hello.c
I have seen many programs consisting of structures like the one below typedef struct
Many programs include an auto-updater, where the program occasionally looks online for updates, and
Many programs have created a huge amount of swap files. They annoy me, because
I have a Qt program with many buttons, user-interactable widgets, etc. At one stage
I have inherited a 20-year-old interactive command-line unix application that is no longer supported
Many times I found out that I need a software to create simple educational
I have built many c# programs over the last few years, and I'm confident
In many applications, we have some progress bar for a file download, for a
(1) At the bottom line: what does it all have to take to in

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.