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 261 views
2 answers 336 views
1 answer 180 views
1 answer 225 views
225 views asked Apr 9, 2018 by avibootz
1 answer 281 views
1 answer 324 views
1 answer 422 views
...