0

I'm having my head around for a couple of days with this question, and I still can't solve my problem.

If I need to read two strings from keyboard I can do this:

cin >> str1 >> str2;

However I want to filter the input.

What I'm trying to do, is something like this:

cin >> filter1 >> str1 >> filter2 >> str2;

or alternatively

cin >> filter1 >> filter2 >> str1 >> str2;

Where filter1 and filter2 are functions with regexes for filter the input.

My biggest trouble is I can't see how to insert the functions, between the input and the strings. .

Any help appreciated

Community
  • 1
  • 1
user7140484
  • 920
  • 6
  • 14

1 Answers1

0

Your filter function should return object of class that implements filtering using regex. Then you would overload operator>> to accept that object, which would read data and invoke it. Peek into istream header to get idea how to do that. Object must be destroyed or it may be a singleton of some kind

Swift - Friday Pie
  • 12,777
  • 2
  • 19
  • 42