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 165 views
2 answers 223 views
1 answer 92 views
1 answer 139 views
139 views asked Apr 9, 2018 by avibootz
1 answer 169 views
1 answer 190 views
1 answer 220 views
...