How to use cin manipulator to skip the first N characters from input in C++

1 Answer

0 votes
#include <iostream>

using namespace std;

istream &skip4chars(istream &stream)
{
	char ch;

	for (int i = 0; i < 4; i++) stream >> ch;

	return stream;
}

int main()
{
	char s[30];

	cout << "Enter a string: ";
	cin >> skip4chars >> s;

	cout << s << endl;

	return 0;
}

/*
run:

Enter a string: programming_c++
ramming_c++

*/

 



answered Apr 9, 2018 by avibootz

Related questions

1 answer 157 views
2 answers 216 views
1 answer 84 views
1 answer 129 views
129 views asked Apr 9, 2018 by avibootz
1 answer 159 views
1 answer 181 views
1 answer 212 views
...