[ create a new paste ] login | about

Link: http://codepad.org/sizFIeQb    [ raw code | fork ]

ninwa - C++, pasted on Nov 19:
// Finds all numbers in an input stream and displays them.

#include <iostream>
using namespace std;

int main()
{
	float n = 0;
	char c;

	bool show = false;

	cout << "Enter a number: ";
	while(c = cin.get())
	{
		if(c >= '0' && c <= '9' ){
			n += (((float) c) - 48);
			n *= 10;
			show = true;
		}
		else{
			if(show){
				n /= 10;
				cout << "Number from stream: " << n << endl;
				n = 0;
			}
			show = false;
		}

		if( c == '\n' )
			cout << "Enter a number: ";
	}

	return 0;
}


Create a new paste based on this one


Comments: