How to handle variable number of arguments?

Discussion in 'C++' started by Lambda, Jul 3, 2008.

  1. Lambda

    Lambda Guest

    How to define such a function that:

    1. Accept variable number of std::string arguments,
    can be 1, 2, or 3 arguments.
    2. Find the longest common prefix of all these strings and
    return the position of the end of the longest prefix?
     
    Lambda, Jul 3, 2008
    #1
    1. Advertising

  2. int myfunc(const std::string& first=std::string(),const std::string&
    second=std::string(),const std::string& third=std::string())
    {
    int where;
    bool match=false;
    //do somestuff)
    if(!nomatch)
    return -1;
    return where;
    }

    Lambda wrote:
    > How to define such a function that:
    >
    > 1. Accept variable number of std::string arguments,
    > can be 1, 2, or 3 arguments.
    > 2. Find the longest common prefix of all these strings and
    > return the position of the end of the longest prefix?
     
    Darío Griffo, Jul 3, 2008
    #2
    1. Advertising

  3. Lambda

    Lambda Guest

    On Jul 3, 8:56 pm, Darío Griffo <> wrote:
    > int myfunc(const std::string& first=std::string(),const std::string&
    > second=std::string(),const std::string& third=std::string())
    > {
    > int where;
    > bool match=false;
    > //do somestuff)
    > if(!nomatch)
    > return -1;
    > return where;
    >
    > }
    > Lambda wrote:
    > > How to define such a function that:

    >
    > > 1. Accept variable number of std::string arguments,
    > > can be 1, 2, or 3 arguments.
    > > 2. Find the longest common prefix of all these strings and
    > > return the position of the end of the longest prefix?

    >
    >


    I've never use default argument that way, thanks!
     
    Lambda, Jul 3, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    864
  2. InuY4sha
    Replies:
    6
    Views:
    614
    Antoninus Twink
    Feb 6, 2009
  3. Navaneeth
    Replies:
    4
    Views:
    574
    Kenny McCormack
    Nov 20, 2010
  4. Peter Lauren
    Replies:
    1
    Views:
    618
    Peter Lauren
    May 15, 2011
  5. oldyork90
    Replies:
    10
    Views:
    369
    Jorge
    Sep 27, 2008
Loading...

Share This Page