Freelancer job part time jobs

InstaForex
  • Home
  • Jobs hiring now
  • FAQ
  • Contact

Accepting command line arguments in C++ programming language

January 9, 2011 by Freelance Leave a Comment

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on Google+ (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • More
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pocket (Opens in new window)
  • Click to email this to a friend (Opens in new window)
  • Click to print (Opens in new window)

C++ gives you the privilege to make use of Command Line Arguments. Most important thing is to get aware of the int main(). This gets 2 arguments. First argument is about the number and the second is about the listing procedure of command line arguments.
Its format is given below:

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

In order to count the amount of arguments which are entered in a program coming from command line, int argc is used. Each and everything, related to program even its name is included in it.
All arguments are cataloged in the array having character pointers. Here, argv[0] can be used as the very name of that program. If there is no name then it can be used as an unfilled string. Now, each and every constituent whose number is not greater to argc is called command line argument. It is possible that every argc factor can be used as string. It can also be used as 2 dimensional arrays. Here, argv[argc] can be known as a void pointer.

What will be the way of using it? Approximately, all programs if they like to lay down the limitation of their program can use it. Mostly, it is used in the form of writing a function which gets box file’s name and shows all the manuscript on the screen.
You can make a program like this:

#include <fstream>
#include <iostream>

using namespace std;

int main ( int argc, char *argv[] )
{
  if ( argc != 2 ) // argc must be equal to two for right implementation
    // We print argv[0] Let’s suppose it as a name of the program
    cout<<"usage: "<< argv[0] <<" <filename>\n";
  else {
    // Suppose argv[1] as a filename for opening
    ifstream the_file ( argv[1] );
    // Don’t forget to check that the file is completely opened
    if ( !the_file.is_open() )
      cout<<"File can’t be opened\n";
    else {
      char x;
      // the_file.get ( x ) it gives back false, when there is fault or file is finished            while ( the_file.get ( x ) )
        cout<< x;
    }
    // the execution of the file is stopped now
  }
}

The program is straightforward. It includes the complete edition of main. The next thing is to make sure whether a user has given 2nd argument or not. After that, it is the liability of the program to verify the file by giving the command of open. This process is trouble-free and authentic. The file will be opened by command, if it has no fault. It is easy to identify the code but comments are given for your ease. The reason is that, you will feel unproblematic while learning the command line argument.

100% Bonus

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on Google+ (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • More
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pocket (Opens in new window)
  • Click to email this to a friend (Opens in new window)
  • Click to print (Opens in new window)
How to use Functions in C++ programming language
Functions with variable-length argument lists in C++ programming language
The C Preprocessor in C++ programming language
Using ofstream and ifstream as main input output C programming classes
Introduction to Classes in C++ programming language
Basic lesson for C++ programming language
Recursion in C++ programming language
Include code in PHP language
Functions in C++ programming language
Templates and Templated Classes in C++ programming language
How to use Switch Case in C++ programming language
Array basics in C programming language
How to install Ruby on rails ?

Filed Under: C++

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

CAPTCHA
Refresh

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Earn money as trader

Bonds

Earn from home ads

HotForex Bonus

Work from home ads

img

Work from home as instaforex forex trader

Freelance categories

  • Earn money as webmaster
    • Advertising
    • Affiliate program
    • Amazon
    • Bidvertiser
    • Blogging
    • Facebook
    • Google Adsense
    • Hosting
    • Komoona
    • LinkedIn
    • Neteller
    • SEO
    • Skrill Moneybookers
    • Twitter
  • Education
    • How to do
    • Job description glossary
    • Wordpress how to do
  • Freelancer advice tips
    • Forex trading from home
      • Affiliate programs
        • 500affiliates
        • Avapartner
        • Etoropartners affiliate program
        • HotForex Affiliate program HFaffiliates
      • Binary options trading
        • Anyoption
        • OptionBit Review
        • TradeRush
        • Ubinary
        • Yesoption
      • Facebook IPO price – buy facebook stock
      • Forex brokers reviews
        • 4XP Review
        • Alpari Russia Review
        • Alpari UK
        • AvaTrade Review
          • AvaFx Review
        • DeltaStock Review
        • Directfx Review
        • DukaScopy Review
        • Easy Forex Review
        • Etoro Review
        • ETX Capital Review
        • Exness
        • Forex.com Review
        • Forex4you
        • ForexYard Review
        • FXCM Review
        • FXDD Review
        • FxOpen Review
        • Fxpro Review
        • HiWayFX review
        • Hotforex Review
        • HY Markets Review
        • IC Markets Forex Review
        • IFC Market
        • IForex Review
        • IG Markets
        • Instaforex Review
        • Ironfx Review
        • Keystock Review
        • LCG review
        • Liteforex broker
        • Marketiva Review
        • Markets.com Review
        • NordFx Review
        • Pepperstone Review
        • Plus500 review
        • Roboforex
        • SwissQuote Bank Review
        • Thinkforex
        • UFX Markets review
        • Windsor Brokers Review
        • XeMarkets Review
        • xForex
        • Xtrade Review
        • Youtrade FX Review
        • Zulutrade Review
    • Freelance glossary
    • Freelance Programming tips
    • Learn about programming
      • C++
      • Linux
      • PHP
      • Ruby on rails
      • SQL
    • Top freelance websites
    • Web Design tips
    • Work from home business
    • Writing tips
  • Freelancer job news
    • Job advice
    • Thinking
    • Worldwide job offers
  • IT news
  • Jobs

Best Forex Brokers Reviews

  • Avafx Review – how to earn in forex market using Avafx Forex Broker
  • Avatrade Review
  • eToro Review
  • Alpari NZ Review
  • InstaForex Review
  • DukaScopy Review – Swiss bank Forex broker
  • Forex.com Review – how to earn money in forex market as trader
  • Ironfx Review
  • FXCM Review
  • FxOpen Review
  • Hotforex Review
  • Markets.com Review
  • UFX Markets Review
  • Zulutrade Review – earn money using free forex signals where forex experts trade for you
  • Exness forex broker Review
  • Fxpro Review
  • LiteForex forex broker review
  • NordFx Review and bonus
  • Roboforex forex broker Review
  • XM.com Review - Xemarkets forex broker review

Navigation

  • Home
  • Jobs hiring now
  • FAQ
  • Contact

Languages

  • Arabic language
  • Bengali language
  • Communiqué de presse
  • China language
  • Pressemitteilung
  • Japanese language
  • Comunicado de imprensa
  • Russian language
  • Presione soltar
  • Turkish
  • Comunicato stampa
  • Hindi language

Recent articles

  • IronFX Review
  • How to earn money as freelancer ?
  • LCG broker Review
  • Forex vs. stocks – Which is a Better for Trading ?
  • Thinkmarkets Review
Freelancer job - Copyright 2007
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.