using cin.ignore() question

Oct 13, 2015 at 2:09am
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 Oct 13, 2015 at 2:11am
Oct 13, 2015 at 2:12am
if it helps my goal is to do something like this.
input:abh fte wwl kql zto
output:hello
Oct 13, 2015 at 2:13am
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
Oct 13, 2015 at 2:24am
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.
Oct 13, 2015 at 3:48am
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.

Oct 13, 2015 at 4:24am
Hello jlb! I am trying to make a decoder program for null ciphers. If I may ask does .substr() work similarly to ignore()?
Oct 13, 2015 at 4:46am
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.