Connecting Tech Pros Worldwide Help | Site Map

How to handle variable number of arguments?

  #1  
Old July 3rd, 2008, 01:45 PM
Lambda
Guest
 
Posts: n/a
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?
  #2  
Old July 3rd, 2008, 02:05 PM
=?ISO-8859-1?Q?Dar=EDo_Griffo?=
Guest
 
Posts: n/a

re: How to handle variable number of arguments?


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:
Quote:
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?
  #3  
Old July 3rd, 2008, 02:35 PM
Lambda
Guest
 
Posts: n/a

re: How to handle variable number of arguments?


On Jul 3, 8:56*pm, Darío Griffo <dario.griffo.lis...@gmail.comwrote:
Quote:
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:
Quote:
How to define such a function that:
>
Quote:
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!
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
"how to split a string in a random way" Pascal answers 12 December 16th, 2006 02:05 AM
Cannot return values of char variable Pedro Pinto answers 18 November 4th, 2006 07:55 AM
Variadic functions calling variadic functions with the argument list, HLL bit shifts on LE processors Ross A. Finlayson answers 19 November 14th, 2005 07:59 PM
variable number of arguments The Directive answers 10 November 14th, 2005 01:34 AM
Variable number of arguments when calling a DLL function Vince answers 3 July 22nd, 2005 10:46 PM