Lasciamo perdere ... se usi il C++ potresti anche scrivere diversamente (ecco tutto l'esempio, almeno le parti importanti ...)

codice:
#include <sstream>


...


	istringstream iss(str1);
	string tok;
	int value;
	while (getline(iss, tok, ' '))
	{
		istringstream(tok) >> value;


		cout << value << endl;
	}