0

Hey guys, first post here so go easy. Ha.

I am writing a program that needs to take command line arguments, a number and 2 characters.
However, if one of the chars is a command line specific char (such as #, &) it must produce an error.
Does the isgood() function tell which chars are valid or not? or is there a similar function that i could use?

Any help appreciated

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Salem
0

> Does the isgood() function tell which chars are valid or not?
> or is there a similar function that i could use?
no, the closest you have is

template<typename char_type> 
  std::ispunct( const char_type&, const std::locale& ) ;

but you could easily write one of your own:

#include <string>

inline bool isgood( char c )
{
  static const std::string bad_chars = "!@#$><&" ; // etc
  return bad_chars.find( c, 0 ) == std::string::npos ;
}
0

Sounds just like this thread
http://www.daniweb.com/forums/thread115791.html

> if one of the chars is a command line specific char (such as #, &) it must produce an error.
Chances are, the shell will have already used it (see other thread) before it gets to your program.
Unless you quote your shell meta characters in some way, your program won't see them.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.