input file

how do you cin input is digit or letter? I am trying ask use to input from keyboard but i dont like !@#$%^&* only letter and digit

I try isalnum isdigit, isalpha. It say it can convert from string to int
Take a look at the link below:

http://www.cplusplus.com/forum/beginner/175574/


It may point you to the right direction
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <stdlib.h>
#include <string>

using namespace std;

int main(){
// cin is a standard input command. Pronouned "C - in" You can use it for numbers or characters
// cout  is a standard output command. Pronouned "C - out" It prints to the screen
// So cin can do either, what is important is your variable declaration

string demo1="";
int demo2=0;



cout << "Enter a few letters" << endl;
cin >> demo1;
cout << "Hey you typed "<< demo1 << endl;

cout << "\n\n\n";

cout << "Type a few numbers." <<endl;
cin >> demo2;
cout << "Does the number " << demo2 << " mean anything to you?"<< endl;

return 0;
}
Last edited on
Topic archived. No new replies allowed.