Using cin.putback() in different compilyators

Hello to all.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <cstring>
using namespace std;

int main ()
{
	while (cin) {
		char ch;
		do {
			cin.get (ch);
			if (ch=='_') {
				cin.putback('6');
				cin.putback('5');
				cin.putback('4');
				cin.putback('3');
				cin.putback('2');
				cin.putback('1');
			}
		} while (ch != '\n' && isspace (ch));
		cout << ch;
	}
}


This code compiled in g ++, gives the following result:

1
2
3
4
debianpc:/# c++ test.cpp 
debianpc:/# ./a.out
abc_abc
abc_123456abc


But in other compilers:

1
2
3
c:\test.exe
abc_abc
abc_1456abc


In what the hitch is covered? (Sorry for bad english)
Last edited on
Topic archived. No new replies allowed.