isalpha and ispunct work punctiliously, but isspace spaces out.

cout << "Please enter an integer: ";
	cin	 >> str;
	int bogus = 0;
	for (int i = 0; i < str.length(); i++)
	{
		char temp = str.at(i);
		if (isalpha(temp) || isspace(temp) || ispunct(temp))
		{
			cout	<< "Please try again!"	<< endl;
			cout	<< "The bad character is "	<< temp	<< endl;
			bogus++;
			break;
		}
	}
	if (bogus < 1)
		cout	<< "Succeeded with "	<< str	<< endl;

Rich

You realize that the >> operator for input is is default delimited on whitespace, right?

> cin >> str;
This won't read a string with spaces - it uses spaces for a delimiter to begin with.

Use getline() to read a whole line - spaces and all, then try.

I knew it, then forgot it. Thanks - it's fixed.

Yup, you're right - I had gotten too used to using cin for everything. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.