I am trying to set up a delimiter character string for the input stream
such that the delimiter string is "skipped over" in the input stream.
Can someone suggest how to do this with some sample code? I am
attaching a "C" code snippet that does the same thing. The problem is
that I don't know how to realize this using "cin"
Thanks,
Lee

I am trying to set up a delimiter character string for the input stream such that the delimiter string is "skipped over" in the input stream. Can someone suggest how to do this with some sample code? I am attaching a "C" code snippet that does the same thing. The problem is that I don't know how to realize this using "cin"
Thanks, Lee

I am trying to set up a delimiter character string for the input streamsuch that the delimiter string is "skipped over" in the input stream.Can someone suggest how to do this with some sample code? I amattaching a "C" code snippet that does the same thing. The problem isthat I don't know how to realize this using "cin"
Thanks,Lee

/****************************/#include <stdio.h>

intmain(){ int abc, xyz;

printf("Enter the values: ");

scanf("%d Step over this text %d", &abc, &xyz);

printf("VAR1: %d\n", abc); printf("VAR2: %d\n", xyz);}

I would use the std::getline function which takes an istream &, a
string &, and optionally a delimiter character as arguments.

The first overload, taking just the first two arguments, reads an
entire line up to the new line character or EOF, whichever comes
first. The second overload will use the character you give it as a
delimiter. It is quite flexible as you don't have to know ahead of
time exactly how many elements between delimiters there might be ...
but 99% of the time you'll probably need to know, anyway.

One caveat ... I think the Borland 5 compiler (i.e. the RogueWave STL
libraries it uses) has troubles with this particular getline
function...if that's what you are using, you can fall back on
std::istream::getline which takes a buffer (i.e. char*) and a length
and an optional delimiter as arguments. Works just fine on my other
compilers, though...

This is not quite the same thing. The suggested approach does not
distinguish between "Step over this text" and any other four-word
string. Is there no easy way to realize this using the streaming
library of C++?

This is not quite the same thing. The suggested approach does not distinguish between "Step over this text" and any other four-word string. Is there no easy way to realize this using the streaming library of C++?

I am trying to set up a delimiter character string for the input stream such that the delimiter string is "skipped over" in the input stream. Can someone suggest how to do this with some sample code? I am attaching a "C" code snippet that does the same thing. The problem is that I don't know how to realize this using "cin"
Thanks, Lee

/****************************/ #include <stdio.h>

int main() { int abc, xyz;

printf("Enter the values: ");

scanf("%d Step over this text %d", &abc, &xyz);

printf("VAR1: %d\n", abc); printf("VAR2: %d\n", xyz); }

C++ doesn't come bundled with that functionality, that I know of.

Here's a quick implementation that more or less matches the scanf
functionality, and a tiny test program. If the ignored string is
not matched, it sets ios::failbit for the input stream.

I am trying to set up a delimiter character string for the input stream such that the delimiter string is "skipped over" in the input stream. Can someone suggest how to do this with some sample code? I am attaching a "C" code snippet that does the same thing. The problem is that I don't know how to realize this using "cin"
Thanks, Lee

The correct way to handle this is to define an input stream manipulator
that accepts the "delimiter string" as an argument. This manipulator
should intelligently handle optional delimiter characters. If the
manipulator encounters the "delimiter string", it steps over it. If
not, it stores the value read into a "shared buffer", as described in
K&R Section 4.3. During reading, attempt is made to first read from
the "shared buffer" and then the input stream. Of course, this
requires changing the way the extraction operator works, which will not
happen unless this idea makes it to the standard.

We all know that manipulators that accept arguments are a little tricky
(The C++ Programming Language, Bjarne Stroustrup, 3rd Edition, Section
21.4.6.1) The way it is done is to define a class/structure that has
the overloaded operator >> friend function. This overloaded function
accepts the reference to the input stream and the reference to an
object of the aforementioned class/structure as arguments, and returns
the reference to the input stream. Here's an example:

For completeness, here's a code snippet for a manipulator that does not
take arguments. All that is needed here is a function that accepts the
reference to the input stream as an argument, and returns the reference
to the input stream.