C++ bigginer question

hi all,

i am a programmer doing .net for long time. Now i would like to learn c++ and explore more in the programming world. I just started learing that and found this web site pretty cool. So thought of starting from here. You may see several questions from me going forward.

Now I had a question related to numerics.

How can we check the entered value from a console application is numeric or not?

Could anybody please walk me thru in learing c++.

Thanks all in advance for your patience & help.
To check if the entered value from a console application is numeric or not you can use the following "isnum(string)" function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream.h>
#include <ctype.h>	// function isdigit(char) need this inclusion

bool isnum(string str) {
	bool res = true;
	char * s = str.begin();
	for(unsigned int i = 0; i < str.length(); i++)
		res = res && isdigit(s[i]);
	return res;
}

void main() {
	string input;
	while(true) {
		cout << "enter something: ";
		cin >> input;
		if(isnum(input))
			cout << "numeric";
		else
			cout << "alphanumeric";
		cout << endl;
	}
}
Last edited on
i'm beginner in c++ too. i wanna askin' somethin':
if i wrote this kinda code is it will work?
1
2
3
4
5
6
7
8
9
//this is at the first time entry been entered into program, i count the time like //time like this

c = __TIME__;

//and after 5 minutes later:
d = __TIME__;

//and then i'm doin' :
e = d - c;

is it valid operations?
Topic archived. No new replies allowed.