using cin.ignore() question

how do i go about getting the cin.ignore(2) to ignore every two characters instead of just the first two characters of input?

while (!cin.eof())
{


cin.ignore(2);
cin.getline(c, 100);

cout <<c<<endl;

}
Last edited on
if it helps my goal is to do something like this.
input:abh fte wwl kql zto
output:hello
i just realized that if i figure out how to get it ignore every two characters i run into a problem of having spaces counted as character too
okay so i think if i put cin.ignore() into a for loop i can get it to ignore 2 characters more than once and i can set the for loop limit by getting the number of characters that was inputted and dividing it by 2.
What exactly are you trying to accomplish?

Using ignore() in this case is probably the wrong way to go. You may want to look into string streams, string.substr() instead.

Hello jlb! I am trying to make a decoder program for null ciphers. If I may ask does .substr() work similarly to ignore()?
No. The way you're trying to use ignore() is trying to remove the irrelevant characters at entry time (preprocessing). I'm suggesting that you think about post processing the user input. The std::string class has quite a few member functions that should make processing a string that contains the user input much easier. I just suggested a couple of methods but remember the std::string class has quite a few member functions to aid in processing strings.

So instead of trying to force the iostream class to process the input, save the input to a string and process that string.

Topic archived. No new replies allowed.